Skip to main content

Interface: IChartingLibraryWidget

Charting Library.IChartingLibraryWidget

The main interface for interacting with the library, returned by ChartingLibraryWidgetConstructor. For more information, refer to the Widget methods article.

Methods

activeChart

activeChart(): IChartWidgetApi

Get an API object for interacting with the active chart. For example, you can subscribe to events on the active chart, such as IChartWidgetApi.onIntervalChanged. Note that the library does not manage the event subscriptions when users switch between the charts on the multiple-chart layout. If necessary, you should manually unsubscribe from the previous chart and subscribe to the newly selected one. To track the currently active chart, use the SubscribeEventsMap.activeChartChanged event.

Returns

IChartWidgetApiAn API object for interacting with the chart.


activeChartIndex

activeChartIndex(): number

Get the index of the active chart in the layout.

Returns

numbernumber.


addCustomCSSFile

addCustomCSSFile(url): void

Add a custom CSS file for the library to load.

Parameters

NameTypeDescription
urlstringA url to the custom CSS file. Should be absolute or relative to the static folder.

addCustomJSFile

addCustomJSFile(url): void

Trading Platform only. Add a custom JavaScript module for the library to load inside its iframe. See also TradingTerminalWidgetOptions.custom_js_urls.

The file is loaded as a <script type="module"> element, so it can use import statements to load further files, and register custom elements such as the tv-custom-timescale-mark and tv-custom-bar-mark elements used for custom mark tooltips.

Security warning: the module runs with full access to the page origin and is treated as trusted code. Only load files that you control, and never construct the URL from user input.

Parameters

NameTypeDescription
urlstringA URL to the custom JavaScript file. Should be absolute, or relative to ChartingLibraryWidgetOptions.library_path.

applyOverrides

applyOverrides<TOverrides>(overrides): void

Apply overrides to all charts currently in the widget without reloading. See also ChartingLibraryWidgetOptions.overrides.

Type parameters

NameType
TOverridesextends Partial<ChartPropertiesOverrides>

Parameters

NameTypeDescription
overridesTOverridesAn object of overrides to apply to the chart(s).

Returns

void

widget.applyOverrides({"paneProperties.legendProperties.showLegend": false});

If you want to apply overrides to a specific chart only, use IChartWidgetApi.applyOverrides instead.


applyStudiesOverrides

applyStudiesOverrides(overrides): void

Apply overrides to indicator styles and inputs without reloading. Refer to Indicator Overrides for more information. Overrides for built-in indicators are listed in StudyOverrides.

Parameters

NameTypeDescription
overridesobjectAn object of overrides to apply to the studies.

applyTradingCustomization

applyTradingCustomization(tradingCustomization): Promise<void>

Apply overrides to the order and position lines created either using the Broker API or trading primitives methods.

Parameters

NameType
tradingCustomizationTradingCustomization

changeTheme

changeTheme(themeName, options?): Promise<void>

Change the theme of the chart.

Parameters

NameTypeDescription
themeNameThemeNameA theme name.
options?ChangeThemeOptionsAn optional object of options for the theme.

Returns

Promise<void>A promise that resolves when the theme has been changed.


chart

chart(index?): IChartWidgetApi

Get an API instance that can be used to interact with a chart.

Parameters

NameTypeDescription
index?numberZero based index of the chart.

Returns

IChartWidgetApiAn API instance.


chartReady

chartReady(): Promise<void>

A promise that resolves when the chart is ready to be used.


chartsCount

chartsCount(): number

Get the number of charts in the current layout.

Returns

numberA count of the charts in the current layout.


clearUndoHistory

clearUndoHistory(): void

Clears the undo & redo history.

Warning: this should only be used in very specific cases where you have considered the UX implications. It is generally unexpected for the user that the undo history has been cleared.

An example of an acceptable use-case would be reusing a chart when switching pages / tabs on a Single Page Application, and presenting it to the user as a new chart.


closePopupsAndDialogs

closePopupsAndDialogs(): void

Close all open context menus, pop-ups or dialogs.


createButton

createButton(options?): HTMLElement

Create a button in the top toolbar. This should be called after headerReady has resolved.

Parameters

NameTypeDescription
options?CreateHTMLButtonOptionsA optional object of options for the button.

Returns

HTMLElementA HTMLElement you can customize.

widget.headerReady().then(function() {
var button = widget.createButton();
button.setAttribute('title', 'My custom button tooltip');
button.addEventListener('click', function() { alert("My custom button pressed!"); });
button.textContent = 'My custom button caption';
});

createButton(options): string

Create a button in the top toolbar. This should be called after headerReady has resolved. If the title option is provided then the title text will be shown in a tooltip on hover. If the onClick option is provided then the button will be clickable.

Parameters

NameTypeDescription
optionsCreateTradingViewStyledButtonOptionsA object of options for the button.

Returns

stringA string button id

createButton(options?): string | HTMLElement

Create a button in the top toolbar. This should be called after headerReady has resolved.

Parameters

NameTypeDescription
options?CreateButtonOptionsA optional object of options for the button.

Returns

string | HTMLElementA HTMLElement if the useTradingViewStyle option is false or undefined. string(button id) if useTradingViewStyle is true.


createDropdown

createDropdown(params): Promise<IDropdownApi>

Add a custom dropdown menu to the top toolbar.

Parameters

NameType
paramsDropdownParams

Returns

Promise<IDropdownApi>

widget.createDropdown(
{
title: 'dropdown',
tooltip: 'tooltip for this dropdown',
items: [
{
title: 'item#1',
onSelect: () => {console.log('1');},
},
{
title: 'item#2',
onSelect: () => {widget.activeChart().setSymbol('IBM').then(() => widget.activeChart().setResolution('1D'));},
},
{
title: 'item#3',
onSelect: () => {
widget.activeChart().createStudy(
'MACD',
false,
false,
{
in_0: 14,
in_1: 30,
in_3: 'close',
in_2: 9
}
);
},
}
],
icon: `<svg xmlns="http://www.w3.org/2000/svg" width="28" height="28"><g fill="none" stroke="currentColor"><circle cx="10" cy="10" r="2.5"/><circle cx="18" cy="18" r="2.5"/><path stroke-linecap="square" d="M17.5 7.5l-7 13"/></g></svg>`,
}
).then(myDropdownApi => {
// Use myDropdownApi if you need to update the dropdown:
// myDropdownApi.applyOptions({
// title: 'a new title!'
// });

// Or remove the dropdown:
// myDropdownApi.remove();
});

crosshairSync

crosshairSync(): IWatchedValue<boolean>

Only available in Trading Platform. Get a watched value that can be used to read/write/subscribe to the state of the crosshair sync between charts.

Returns

IWatchedValue<boolean>A watched value of the state of the crosshair sync.

widget.crosshairSync().setValue(true);

currencyAndUnitVisibility

currencyAndUnitVisibility(): IWatchedValue<VisibilityType>

Get a watched value that can be used to read/write/subscribe to the state of the currency and unit visibility setting on the price scale.

Returns

IWatchedValue<VisibilityType>A watched value of the state of the currency and unit visibility option.


customSymbolStatus

customSymbolStatus(): ICustomSymbolStatusApi

Get an API object for creating, and adjusting, custom status items to be displayed within the legend for the main series of each chart.

This can only be accessed when the chart has been created. (headerReady)

Returns

ICustomSymbolStatusApiAn API object for controlling additional custom status items within the legend area.


customThemes

customThemes(): Promise<ICustomThemesApi>

Get a promise that resolves with an API object for interacting with the custom themes. For more information on custom themes, refer to the Custom themes API article.

Returns

Promise<ICustomThemesApi>An API object for interacting with the custom themes.


dateFormat

dateFormat(): IWatchedValue<DateFormat>

Get a watched value that can be used to read/write/subscribe to the state of the date format.

Returns

IWatchedValue<DateFormat>A watched value of the state of the date format.


dateRangeSync

dateRangeSync(): IWatchedValue<boolean>

Only available in Trading Platform. Get a watched value that can be used to read/write/subscribe to the state of the date range sync between charts.

Returns

IWatchedValue<boolean>A watched value of the state of the date range sync.

widget.dateRangeSync().setValue(true);

drawOnAllChartsEnabled

drawOnAllChartsEnabled(): IWatchedValue<boolean>

Get a watched value that read/write/subscribe to the state of the 'draw on all charts' mode.

When enabled new drawings will be replicated to all charts in the layout and shown when the same ticker is selected.

Returns

IWatchedValue<boolean>


exitFullscreen

exitFullscreen(): void

Set the chart into non-fullscreen mode (if it isn't already).


getCSSCustomPropertyValue

getCSSCustomPropertyValue(customPropertyName): string

Returns the current value for a CSS custom property.

Example:

const currentValue = widget.getCSSCustomPropertyValue('--my-theme-color');

Parameters

NameTypeDescription
customPropertyNamestringA string representing the CSS custom property name to be checked. It is expected that the name should start with a double hyphen ('--').

Returns

stringA string containing the value of the property. If not set, returns the empty string.


getIntervals

getIntervals(): string[]

Get an array of supported intervals (resolutions).

Returns

string[]An array of supported intervals. E.g. ['1D', '5D', '1Y'].


getLanguage

getLanguage(): LanguageCode

Get the configured locale of the widget. For example en, zh, ru.

Returns

LanguageCodeA code representing the locale of the widget.


getSavedCharts

Get a list of chart descriptions saved to the server for the current user.

Returns

Promise<SaveLoadChartRecord[]>A promise that resolves with an array of saved chart information.

Deprecated

getSavedCharts(callback): void

Deprecated

Use getSavedCharts instead.

Get a list of chart descriptions saved to the server for the current user.

Parameters

NameTypeDescription
callback(chartRecords: SaveLoadChartRecord[]) => voidA function called with an array of saved chart information as the first argument.

getStudiesList

getStudiesList(): string[]

Get an array of the names of all supported studies. These names can be used when calling IChartWidgetApi.createStudy.

Returns

string[]An array of supported study names. E.g. ['Accumulation/Distribution', 'Accumulative Swing Index', 'Advance/Decline', ...].


getStudyInputs

getStudyInputs(studyName): StudyInputInformation[]

Get an array of information about indicator inputs, including their names. You need to know an input name to refer to this property in the code. For example, when you change an input value using the overrides. Consider the Input property section for more information.

Parameters

NameTypeDescription
studyNamestringThe name of a study.

Returns

StudyInputInformation[]


getStudyStyles

getStudyStyles(studyName): StudyStyleInfo

Get information about indicator properties. You can use this information to refer to the properties in the code. For example, when you change property values using the overrides.

Note that getStudyStyles does not return actual property names but the indicator's metadata. Consider the Property path section for more information on how to refer to the properties.

Parameters

NameTypeDescription
studyNamestringThe name of a indicator.

Returns

StudyStyleInfo


getTheme

getTheme(): ThemeName

Get the current theme of the chart.

Returns

ThemeNameA theme name. The name of the current theme.

console.log(widget.getTheme());

headerReady

headerReady(): Promise<void>

A promise that resolves if and when the header is ready to be used.


hideAllDrawingTools

hideAllDrawingTools(): IWatchedValue<boolean>

Get a watched value that can be used to read/write/subscribe to the state of the "hide all drawing tools" button.

Returns

IWatchedValue<boolean>A watched value of the state of the "hide all drawing tools" button.


intervalSync

intervalSync(): IWatchedValue<boolean>

Only available in Trading Platform. Get a watched value that can be used to read/write/subscribe to the state of the interval sync between charts.

Returns

IWatchedValue<boolean>A watched value of the state of the interval sync.

widget.intervalSync().setValue(true);

layout

layout(): LayoutType

Get the current chart layout type.

Returns

LayoutTypeA string representation of the current layout type. E.g. '2h' for two charts split vertically.


layoutName

layoutName(): string

Get the name of the current chart layout. The return value will be undefined if the current layout has not been saved.

Returns

stringA string of the name of the current chart layout.


load

load(state, extendedData?): Promise<void>

Loads the chart state from an object. This method is part of the low-level save/load API.

Parameters

NameTypeDescription
stateobjectA chart state object to load.
extendedData?SavedStateMetaInfoA optional object of information about the saved state.

loadChartFromServer

loadChartFromServer(chartRecord): Promise<void>

Load a saved chart from the server.

Parameters

NameTypeDescription
chartRecordSaveLoadChartRecordA chart information object (returned by getSavedCharts).

lockAllDrawingTools

lockAllDrawingTools(): IWatchedValue<boolean>

Get a watched value that can be used to read/write/subscribe to the state of the "lock all drawing tools" button.

Returns

IWatchedValue<boolean>A watched value of the state of the "lock all drawing tools" button.


magnetEnabled

magnetEnabled(): IWatchedValue<boolean>

Get a watched value that can be used to read/write/subscribe to the state of the magnet.

Returns

IWatchedValue<boolean>A watched value of the state of the magnet.


magnetMode

magnetMode(): IWatchedValue<number>

Get a watched value that can be used to read/write/subscribe to the state of the magnet mode.

Returns

IWatchedValue<number>A watched value of the state of the magnet mode.


mainSeriesPriceFormatter

mainSeriesPriceFormatter(): INumberFormatter

Get the price formatter for the main series. You can use this to format prices as the char

Returns

INumberFormatter


navigationButtonsVisibility(): IWatchedValue<VisibilityType>

Get a watched value that can be used to read/write/subscribe to the state of the navigation buttons.

Returns

IWatchedValue<VisibilityType>A watched value of the state of the navigation buttons.


news

news(): Promise<INewsApi>

Trading Platform only. Get a promise that resolves with an API object for interacting with the widgetbar (right sidebar) news widget.

Returns

Promise<INewsApi>An API object for interacting with the widgetbar (right sidebar) widget.


onChartReady

Deprecated

onChartReady(callback): void

Deprecated

Use chartReady instead.

The library will call callback when the chart is ready to be used.

Parameters

NameTypeDescription
callbackEmptyCallbackA function that will be called when the chart is ready to be used.

onContextMenu

onContextMenu(callback): void

The widget will call the callback function each time the widget wants to display a context menu. See also ChartingLibraryWidgetOptions.context_menu.

Parameters

NameTypeDescription
callback(unixTime: number, price: number) => ContextMenuItem[]A function called with the time and price of the location on the chart that triggered the context menu. The array of objects returned will add or remove items from the context menu.

Returns

void

widget.chartReady().then(function() {
widget.onContextMenu(function(unixtime, price) {
return [{
position: "top",
text: "First top menu item, time: " + unixtime + ", price: " + price,
click: function() { alert("First clicked."); }
},
{ text: "-", position: "top" }, // Adds a separator between buttons
{ text: "-Paste" }, // Removes the existing item from the menu
{
position: "top",
text: "Second top menu item 2",
click: function() { alert("Second clicked."); }
}, {
position: "bottom",
text: "Bottom menu item",
click: function() { alert("Third clicked."); }
}];
});
});

onGrayedObjectClicked

onGrayedObjectClicked(callback): void

The library will call callback when a greyed-out drawing tool or study is clicked.

Parameters

NameTypeDescription
callback(obj: GrayedObject) => voidA function that will be called when a greyed-out drawing tool or study is clicked.

onShortcut

onShortcut(shortCut, callback): void

This method specifies an action that happens when a user presses certain keys. It allows you to override the built‑in shortcuts or specify custom ones.

To do this, pass a keyboard shortcut and a callback function as parameters. The library invokes the callback when the shortCut keys are pressed.

Note that the shortCut argument depends on the key types. Refer to the Manage shortcuts section for more information and examples.

Non-modifier keys must be passed as numeric key codes. String key names, such as "alt+q", are not supported and throw an error. Only the modifier keys (ctrl, shift, alt, and meta/cmd/command) can be passed as strings.

Parameters

NameTypeDescription
shortCutnumber | (string | number)[]A numeric key code, or an array of string modifiers and numeric key codes, e.g. ['ctrl', 'shift', 75].
callbackEmptyCallbackA function that is called when the shortCut keys are pressed.

paneButtonsVisibility

paneButtonsVisibility(): IWatchedValue<VisibilityType>

Get a watched value that can be used to read/write/subscribe to the state of the pane buttons.

Returns

IWatchedValue<VisibilityType>A watched value of the state of the pane buttons.


remove

remove(): void

Remove the widget and all its data from the page. The widget cannot be interacted with after it has been removed.


removeButton

removeButton(buttonIdOrHtmlElement): void

Remove a button from the top toolbar. This should be called after headerReady has resolved.

Parameters

NameTypeDescription
buttonIdOrHtmlElementstring | HTMLElementThe button link or id that you receive from createButton method.

Returns

void

widget.headerReady().then(function() {
var button = widget.createButton();
widget.removeButton(button)
});

removeChartFromServer

Remove a saved chart from the server.

Parameters

NameTypeDescription
chartIdstring | numberA chart ID from a SaveLoadChartRecord (returned by getSavedCharts).

Returns

Promise<void>A promise that resolves when the chart is removed.

Deprecated

removeChartFromServer(chartId, onCompleteCallback): void

Deprecated

Remove a saved chart from the server.

Parameters

NameTypeDescription
chartIdstring | numberA chart ID from a SaveLoadChartRecord (returned by getSavedCharts).
onCompleteCallbackEmptyCallbackA callback function called when the chart is successfully removed.

resetCache

resetCache(): void

Reset cached bar data from the datafeed, for all symbols.

This has the same effect as calling onResetCacheNeededCallback for all symbol and resolution combinations at once.


resetLayoutSizes

resetLayoutSizes(disableUndo?): void

Resets the sizes of all charts within a multiple-chart layout back to their initial default values. This action redistributes the space equally among all charts to ensure consistency in layout design.

Parameters

NameTypeDescription
disableUndo?booleanWhen set to true, the reset action is not added to the undo stack. Hence, the user cannot undo the reset operation.

save

Saves the chart state to an object. This method is part of the low-level save/load API.

Parameters

NameTypeDescription
options?SaveChartOptionsOptions for customising the saved data.

Returns

Promise<object>A promise that resolves with the chart state.

Deprecated

save(callback, options?): void

Deprecated

Use save instead.

Saves the chart state to an object. This method is part of the low-level save/load API.

Parameters

NameTypeDescription
callback(state: object) => voidA function called with the chart state as the first argument.
options?SaveChartOptionsOptions for customising the saved data.

saveChartToServer

Save the current chart to the server.

Parameters

NameTypeDescription
options?SaveChartToServerOptionsAn optional object of options for saving the chart.

Returns

Promise<void>A promise that resolves when the chart is successfully saved.

If the chart fails to save.

Deprecated

saveChartToServer(onComplete?, onFail?, options?): void

Deprecated

Use saveChartToServer instead.

Save the current chart to the server.

Parameters

NameTypeDescription
onComplete?EmptyCallbackAn optional callback function called when the chart is successfully saved.
onFail?(error: SaveChartErrorInfo) => voidAn optional callback function called when the chart fails to save.
options?SaveChartToServerOptionsAn optional object of options for saving the chart.

selectLineTool

selectLineTool(linetool, options?): Promise<void>

Select an icon. It's the same as clicking on the corresponding button in the left toolbar.

Parameters

NameTypeDescription
linetool"icon"An icon drawing tool.
options?IconOptionsAn optional object with options.

selectLineTool(linetool): Promise<void>

Select a drawing or a cursor. It's the same as clicking on the corresponding button in the left toolbar.

Parameters

NameTypeDescription
linetoolOmit<"icon", SupportedLineTools>A drawing or cursor to select (excluding 'icon')

selectLineTool(linetool, options?): Promise<void>

Select the Icon line tool. It's the same as clicking on the corresponding button in the left toolbar.

Parameters

NameTypeDescription
linetool"icon"Icon line tool.
options?IconOptionsAn optional object with options. Currently only used for the 'icon' drawing.

selectLineTool(linetool, options?): Promise<void>

Select the emoji line tool. It's the same as clicking on the corresponding button in the left toolbar.

Parameters

NameTypeDescription
linetool"emoji"Emoji line tool.
options?EmojiOptionsOptions for the emoji line tool

selectLineTool(linetool, options?): Promise<void>

Select a drawing, icon, or a cursor. It's the same as clicking on the corresponding button in the left toolbar.

Parameters

NameTypeDescription
linetoolSupportedLineToolsA drawing or cursor to select.
options?EmojiOptions | IconOptionsAn optional object with options.

selectedLineTool

selectedLineTool(): SupportedLineTools

Get the currently selected drawing or cursor.

Returns

SupportedLineToolsAn identifier for drawing or cursor.


setActiveChart

setActiveChart(index): void

Set which chart is currently active. It is recommended that this method is only used when linked to a user action which should change the active chart.

Use chartsCount to determine the number of charts currently available. If an invalid index is supplied (less than zero, or greater than the number of charts minus 1) then this method will not change the active chart.

Parameters

NameTypeDescription
indexnumberindex of chart to set as the active chart. Index is zero-based.

setCSSCustomProperty

setCSSCustomProperty(customPropertyName, value): void

Sets the value for a CSS custom property.

Example:

widget.setCSSCustomProperty('--my-theme-color', '#123AAA');

Parameters

NameTypeDescription
customPropertyNamestringA string representing the CSS custom property name. It is expected that the name should start with a double hyphen ('--').
valuestringA string containing the new property value.

setDebugMode

setDebugMode(enabled): void

Enable or disable writing detailed Datafeed API logs into the browser console.

Parameters

NameTypeDescription
enabledbooleanA boolean flag. true to enable debug mode, false to disable.

setLayout

setLayout(layout): void

Set the current chart layout type.

Parameters

NameType
layoutLayoutType

Returns

void

layout A string representation of the new layout type. E.g. '2h' for two charts split vertically.


setLayoutSizes

setLayoutSizes(sizes, disableUndo?): void

Set the sizes of charts within a multiple-chart layout.

Parameters

NameTypeDescription
sizesPartial<LayoutSizes>An object of sizes to set for the charts.
disableUndo?booleanWhen set to true, the set action is not added to the undo stack. Hence, a user cannot undo the size changes.

setSymbol

Deprecated

setSymbol(symbol, interval, callback): void

Deprecated

Set the symbol and resolution of the active chart.

Parameters

NameTypeDescription
symbolstringA symbol to load.
intervalResolutionStringA interval (resolution) to load.
callbackEmptyCallbackA callback. Called when the symbol's data has finished loading.

showConfirmDialog

Show a dialog with custom title and text along with "OK" and "CANCEL" buttons.

Parameters

NameTypeDescription
paramsConfirmDialogParamsA object of options for the created dialog.

Returns

Promise<boolean>A promise that resolves with the confirmation result.

Deprecated

showConfirmDialog(params): void

Deprecated

Use showConfirmDialog instead.

Show a dialog with custom title and text along with "OK" and "CANCEL" buttons.

Parameters

NameTypeDescription
paramsDialogParams<(confirmed: boolean) => void>A object of options for the created dialog.

showLoadChartDialog

showLoadChartDialog(): void

Show the "Load Chart Layout" dialog.


showNoticeDialog

Show a dialog with custom title and text along with an "OK" buttons.

Parameters

NameTypeDescription
paramsNoticeDialogParamsA object of options for the created dialog.

Returns

Promise<void>A promise that resolves when the dialog is closed.

Deprecated

showNoticeDialog(params): void

Deprecated

Use showNoticeDialog instead.

Show a dialog with custom title and text along with an "OK" buttons.

Parameters

NameTypeDescription
paramsDialogParams<() => void>A object of options for the created dialog.

showSaveAsChartDialog

showSaveAsChartDialog(): void

Show the "Copy Chart Layout" dialog.


startFullscreen

startFullscreen(): void

Set the chart into fullscreen mode (if it isn't already).


subscribe

subscribe<EventName>(event, callback): void

Subscribe to library events.

Type parameters

NameType
EventNameextends keyof SubscribeEventsMap

Parameters

NameTypeDescription
eventEventNameA event to subscribe to.
callbackSubscribeEventsMap[EventName]A callback that will be called when the event happens.

supportedChartTypes

supportedChartTypes(): IWatchedValueReadonly<ChartStyle[]>

This method returns a readonly WatchedValue (IWatchedValueReadonly) object that can be used to read/watch the current supported chart types (SeriesType) for an active chart.

The chart type is returned as a number. You can see which number corresponds to which chart type in the Overrides documentation for mainSeriesProperties.style.

Returns

IWatchedValueReadonly<ChartStyle[]>


symbolInterval

symbolInterval(): SymbolIntervalResult

Get the symbol and interval of the active chart.

Returns

SymbolIntervalResult


symbolSync

symbolSync(): IWatchedValue<boolean>

Only available in Trading Platform. Get a watched value that can be used to read/write/subscribe to the state of the symbol sync between charts.

Returns

IWatchedValue<boolean>A watched value of the state of the symbol sync.

if (widget.symbolSync().value()) {
// ...
}

takeClientScreenshot

takeClientScreenshot(options?): Promise<HTMLCanvasElement>

Create a snapshot of the chart and return it as a canvas. Use this method to implement your logic for taking snapshots.

Parameters

NameTypeDescription
options?Partial<ClientSnapshotOptions>An optional object that customizes the returned snapshot.

Returns

Promise<HTMLCanvasElement>A promise containing a HTMLCanvasElement of the snapshot.


takeScreenshot

takeScreenshot(): void

Create a snapshot of the chart and upload it to the server. When it is ready callback functions subscribed to the 'onScreenshotReady' event using subscribe will be called. The URL of the snapshot will be passed as an argument to the callback function.


timeHoursFormat

timeHoursFormat(): IWatchedValue<TimeHoursFormat>

Get a watched value that can be used to read/write/subscribe to the state of the timeHours format.

Returns

IWatchedValue<TimeHoursFormat>


timeSync

timeSync(): IWatchedValue<boolean>

Only available in Trading Platform. Get a watched value that can be used to read/write/subscribe to the state of the time sync between charts.

Returns

IWatchedValue<boolean>A watched value of the state of the time sync.

widget.timeSync().setValue(true);

undoRedoState

undoRedoState(): UndoRedoState

Get the state of the undo/redo stack.

Returns

UndoRedoState


unloadUnusedCharts

unloadUnusedCharts(): void

This method deletes non-visible charts from a multiple-chart layout.

When a user transitions from a layout with a larger number of charts to one with fewer charts, the unused chart APIs still exist behind the scenes. This inherent behavior allows the library to restore previously displayed charts.

If you prefer that additional charts are displayed as new, with no record of previous charts at the same position, you can use this method to delete all non-visible charts. It is most effective to run this method right after a layout change (one can subscribe to SubscribeEventsMap.layout_changed to know when this occurs).

Please ensure that any subscriptions or event listeners associated with the hidden charts are removed prior to invoking this method.

Returns

voidvoid


unsubscribe

unsubscribe<EventName>(event, callback): void

Unsubscribe from library events.

Type parameters

NameType
EventNameextends keyof SubscribeEventsMap

Parameters

NameTypeDescription
eventEventNameA event to unsubscribe from.
callbackSubscribeEventsMap[EventName]A callback to unsubscribe. Must be the same reference as a callback passed to subscribe.

watchList

watchList(): Promise<IWatchListApi>

Trading Platform only. Get a promise that resolves with an API object for interacting with the widgetbar (right sidebar) watchlist.

Returns

Promise<IWatchListApi>An API object for interacting with the widgetbar (right sidebar) watchlist.

const watchlistApi = await widget.watchList();
const activeListId = watchlistApi.getActiveListId();
const currentListItems = watchlistApi.getList(activeListId);
// append new section and item to the current watchlist
watchlistApi.updateList(activeListId, [...currentListItems, '###NEW SECTION', 'AMZN']);

watermark

watermark(): IWatermarkApi

Get an API object for adjusting the watermarks present on the charts. This can only be accessed when the chart is ready to be used. (chartReady)

Returns

IWatermarkApiAn API object for adjusting the watermark settings.


widgetbar

widgetbar(): Promise<IWidgetbarApi>

Trading Platform only. Get a promise that resolves with an API object for interacting with the widgetbar (right sidebar).

Returns

Promise<IWidgetbarApi>An API object for interacting with the widgetbar (right sidebar).