Interface: IChartWidgetApi
Charting Library.IChartWidgetApi
The main chart API.
This interface can be retrieved by using the following widget (IChartingLibraryWidget) methods:
chart(IChartingLibraryWidget.chart)activeChart(IChartingLibraryWidget.activeChart)
Methods
applyLineToolsState
applyLineToolsState(state): Promise<void>
Apply line tools state to the chart which will restore the drawings from the saved content.
This method requires that the saveload_separate_drawings_storage featureset is enabled.
Parameters
| Name | Type |
|---|---|
state | LineToolsAndGroupsState |
applyOverrides
applyOverrides(props): void
Apply overrides to a specific chart instance without reloading. See also ChartingLibraryWidgetOptions.overrides.
Parameters
| Name | Type |
|---|---|
props | object |
Returns
void
Example
widget.chart(0).applyOverrides({"paneProperties.legendProperties.showLegend": false});
If you want to apply overrides to all charts, use IChartingLibraryWidget.applyOverrides instead.
applyStudyTemplate
applyStudyTemplate(template): void
Apply a study template to the chart.
Parameters
| Name | Type | Description |
|---|---|---|
template | object | A study template object. |
Returns
void
Example
widget.activeChart().applyStudyTemplate(template);
availableZOrderOperations
availableZOrderOperations(sources): AvailableZOrderOperations
Get an object with operations available for the specified set of entities.
Parameters
| Name | Type | Description |
|---|---|---|
sources | readonly EntityId[] | An array of entity IDs. |
Returns
Example
widget.activeChart().availableZOrderOperations([id]);
barTimeToEndOfPeriod
barTimeToEndOfPeriod(unixTime): number
Get the bar time to the end of the period
Parameters
| Name | Type | Description |
|---|---|---|
unixTime | number | date timestamp |
Returns
number
bringForward
bringForward(sources): void
Move the sources one level up in the Z-order.
Parameters
| Name | Type | Description |
|---|---|---|
sources | readonly EntityId[] | An array of source IDs. |
Returns
void
Example
widget.activeChart().bringForward([id]);
bringToFront
bringToFront(sources): void
Move the sources to the top of the Z-order.
Parameters
| Name | Type | Description |
|---|---|---|
sources | readonly EntityId[] | An array of source IDs. |
Returns
void
Example
widget.activeChart().bringToFront([id]);
canZoomOut
canZoomOut(): boolean
Check if the chart can be zoomed out using the zoomOut method.
Returns
boolean — true if the chart can be zoomed out.
Example
if(widget.activeChart().canZoomOut()) {
widget.activeChart().zoomOut();
};
canZoomOutWV
canZoomOutWV(): IWatchedValueReadonly<boolean>
Subscription if the chart can be zoomed out using the zoomOut method.
Returns
IWatchedValueReadonly<boolean>
cancelSelectBar
cancelSelectBar(): void
Cancel any active bar selection requests.
Returns
void
Example
widget.activeChart().cancelSelectBar();
chartType
chartType(): SeriesType
Returns the main series style type.
console.log(widget.activeChart().chartType());
Returns
clearMarks
clearMarks(marksToClear?): void
Remove marks from the chart.
Parameters
| Name | Type | Description |
|---|---|---|
marksToClear? | ClearMarksMode | type of marks to clear. If nothing is specified both bar & timescale marks will be removed. |
Returns
void
Example
widget.activeChart().clearMarks();
createAnchoredShape
createAnchoredShape<TOverrides>(position, options): Promise<EntityId>
Create a new anchored drawing. Anchored drawings maintain their position when the chart's visible range changes.
Type parameters
| Name | Type |
|---|---|
TOverrides | extends object |
Parameters
| Name | Type | Description |
|---|---|---|
position | PositionPercents | Percent-based x and y position of the new drawing, relative to the top left of the chart. |
options | CreateAnchoredShapeOptions<TOverrides> | An options object for the new drawing. |
Returns
Promise<EntityId>
Example
widget.activeChart().createAnchoredShape({ x: 0.1, y: 0.9 }, { shape: 'anchored_text', text: 'Hello, charts!', overrides: { color: 'green' }});
For more information, refer to Drawings API.
createExecutionShape
createExecutionShape(): Promise<IExecutionLineAdapter>
Creates a new trade execution on the chart. For more information, refer to Trading primitives.
Starting from version 29, this method is only available in Trading Platform.
Returns
Promise<IExecutionLineAdapter> — An API object for interacting with the execution.
Example
const executionLine = widget.activeChart().createExecutionShape();
executionLine
.setText("@1,320.75 Limit Buy 1")
.setTooltip("@1,320.75 Limit Buy 1")
.setTextColor("rgba(0,255,0,0.5)")
.setArrowColor("#0F0")
.setDirection("buy")
.setTime(widget.activeChart().getVisibleRange().from)
.setPrice(160);
createMultipointShape
createMultipointShape<TOverrides>(points, options): Promise<EntityId>
Create a new multi point drawing.
Type parameters
| Name | Type |
|---|---|
TOverrides | extends object |
Parameters
| Name | Type | Description |
|---|---|---|
points | ShapePoint[] | An array of points that define the drawing. |
options | CreateMultipointShapeOptions<TOverrides> | An options object for the new drawing. |
Returns
Promise<EntityId> — Promise of the ID for the new drawing if it was created successfully.
Example
const from = Date.now() / 1000 - 500 * 24 * 3600; // 500 days ago
const to = Date.now() / 1000;
widget.activeChart().createMultipointShape(
[{ time: from, price: 150 }, { time: to, price: 150 }],
{
shape: "trend_line",
lock: true,
disableSelection: true,
disableSave: true,
disableUndo: true,
text: "text",
}
);
For more information, refer to Drawings API.
createOrderLine
createOrderLine(): Promise<IOrderLineAdapter>
Creates a new trading order on the chart. For more information, refer to Trading primitives.
Starting from version 29, this method is only available in Trading Platform.
Returns
Promise<IOrderLineAdapter> — An API object for interacting with the order.
Example
const orderLine = await widget.activeChart().createOrderLine();
orderLine
.setTooltip("Additional order information")
.setModifyTooltip("Modify order")
.setCancelTooltip("Cancel order")
.onMove(function() {
this.setText("onMove called");
})
.onModify("onModify called", function(text) {
this.setText(text);
})
.onCancel("onCancel called", function(text) {
this.setText(text);
})
.setText("STOP: 73.5 (5,64%)")
.setQuantity("2");
createPositionLine
createPositionLine(): Promise<IPositionLineAdapter>
Creates a new trading position on the chart. For more information, refer to Trading primitives.
Starting from version 29, this method is only available in Trading Platform.
Returns
Promise<IPositionLineAdapter> — An API object for interacting with the position.
Example
const positionLine = await widget.chart().createPositionLine();
positionLine
.onModify(function() {
this.setText("onModify called");
})
.onReverse("onReverse called", function(text) {
this.setText(text);
})
.onClose("onClose called", function(text) {
this.setText(text);
})
.setText("PROFIT: 71.1 (3.31%)")
.setTooltip("Additional position information")
.setProtectTooltip("Protect position")
.setCloseTooltip("Close position")
.setReverseTooltip("Reverse position")
.setQuantity("8.235")
.setPrice(160)
.setExtendLeft(false)
.setLineStyle(0)
.setLineLength(25);
createShape
createShape<TOverrides>(point, options): Promise<EntityId>
Create a new single point drawing.
Type parameters
| Name | Type |
|---|---|
TOverrides | extends object |
Parameters
| Name | Type | Description |
|---|---|---|
point | ShapePoint | A point. The location of the new drawing. |
options | CreateShapeOptions<TOverrides> | An options object for the new drawing. |
Returns
Promise<EntityId> — Promise of the ID for the new drawing if it was created successfully.
Example
widget.activeChart().createShape({ time: 1514764800 }, { shape: 'vertical_line' });
For more information, refer to Drawings API.
createStudy
createStudy<TOverrides>(name, forceOverlay?, lock?, inputs?, overrides?, options?): Promise<EntityId>
Adds an indicator or a symbol for comparison to the chart. For more information, refer to the Indicators article.
Type parameters
| Name | Type |
|---|---|
TOverrides | extends Partial<SingleIndicatorOverrides> |
Parameters
| Name | Type | Description |
|---|---|---|
name | string | name of an indicator as shown in the Indicators widget |
forceOverlay? | boolean | forces the Charting Library to place the created indicator on the main pane |
lock? | boolean | whether a user will be able to remove/change/hide the indicator or not |
inputs? | Record<string, StudyInputValue> | From version v22, it's an object containing named properties from the indicator properties dialog. |
overrides? | TOverrides | An object that contains overrides for a new indicator. Note that you should not specify the indicator name. Overrides for built-in indicators are listed in SingleIndicatorOverrides. |
options? | CreateStudyOptions | study creation options |
Returns
Promise<EntityId> — ID of the created study
createStudyTemplate
createStudyTemplate(options): object
Save the current study template to a object.
Parameters
| Name | Type | Description |
|---|---|---|
options | CreateStudyTemplateOptions | An object of study template options. |
Returns
object — A study template object.
Example
const options = { saveSymbol: true, saveInterval: true };
const template = widget.activeChart().createStudyTemplate(options);
crossHairMoved
crossHairMoved(): ISubscription<(params: CrossHairMovedEventParams) => void>
Get a subscription object for the crosshair moving over the chart.
Returns
ISubscription<(params: CrossHairMovedEventParams) => void> — A subscription object for the crosshair moving over the chart.
Example
widget.activeChart().crossHairMoved().subscribe(
null,
({ time, price }) => console.log(time, price)
);
dataReady
Recommended
dataReady(): Promise<boolean>
Returns a promise that resolves when chart data is loaded. If chart data is already loaded when this method is called, the promise resolves immediately.
Starting from version 32, calling dataReady() without a callback returns a Promise<boolean>.
Code that needs to run after the data is loaded should await the promise. Code that relied on the
previous synchronous boolean return value should be migrated to an explicit synchronous state check.
Returns
Promise<boolean> — A promise that resolves with true when chart data is loaded.
Example
widget.activeChart().dataReady().then(() => {
// ...
});
Deprecated
dataReady(callback): boolean
Use dataReady instead.
Provide a callback function that will be called when chart data is loaded. If chart data is already loaded when this method is called, the callback is called immediately.
Parameters
| Name | Type | Description |
|---|---|---|
callback | () => void | A callback function called when chart data is loaded. |
Returns
boolean
endOfPeriodToBarTime
endOfPeriodToBarTime(unixTime): number
Get the end of period to bar time
Parameters
| Name | Type | Description |
|---|---|---|
unixTime | number | date timestamp |
Returns
number
executeActionById
executeActionById(actionId): void
Execute an action by ID. See Chart methods for more information.
Parameters
| Name | Type | Description |
|---|---|---|
actionId | ChartActionId | An action ID. |
Returns
void
Example
// Undoes the last applied action
widget.activeChart().executeActionById("undo");
// Opens or hides the drawing toolbar
widget.activeChart().executeActionById("drawingToolbarAction");
exportData
exportData(options?): Promise<ExportedData>
Export the current data from the chart.
Parameters
| Name | Type | Description |
|---|---|---|
options? | Partial<ExportDataOptions> | Optional object of options to control the exported data. |
Returns
Promise<ExportedData> — A promise that resolves with the exported data.
Example
// Exports series' data only
widget.activeChart().exportData({ includeTime: false, includedStudies: [] });
// Exports series' data with times
widget.activeChart().exportData({ includedStudies: [] });
// Exports series' data with with user time
widget.activeChart().exportData({ includeTime: false, includeUserTime: true, includedStudies: [] });
// Exports data for the indicator which ID is STUDY_ID
widget.activeChart().exportData({ includeTime: false, includeSeries: false, includedStudies: ['STUDY_ID'] });
// Exports all available data from the chart
widget.activeChart().exportData({ includeUserTime: true });
// Exports series' data before 2018-01-01
widget.activeChart().exportData({ includeTime: false, to: Date.UTC(2018, 0, 1) / 1000 });
// Exports series' data after 2018-01-01
widget.activeChart().exportData({ includeTime: false, from: Date.UTC(2018, 0, 1) / 1000 });
// Exports series' data in the range between 2018-01-01 and 2018-02-01
widget.activeChart().exportData({ includeTime: false, from: Date.UTC(2018, 0, 1) / 1000, to: Date.UTC(2018, 1, 1) / 1000 });
// Exports all displayed data on the chart
widget.activeChart().exportData({ includeDisplayedValues: true });
getAllPanesHeight
getAllPanesHeight(): number[]
Get an array of the heigh of all panes.
Returns
number[] — An array of heights.
Example
console.log(widget.activeChart().getAllPanesHeight());
getAllShapes
getAllShapes(): EntityInfo[]
Get an array of IDs and name for all drawings on the chart.
Returns
EntityInfo[] — An array of drawing information.
Example
widget.activeChart().getAllShapes().forEach(({ name }) => console.log(name));
getAllStudies
getAllStudies(): EntityInfo[]
Get an array of IDs and names for all studies on the chart.
Returns
EntityInfo[] — An array of study information.
Example
widget.activeChart().getAllStudies().forEach(({ name }) => console.log(name));
getCheckableActionState
getCheckableActionState(actionId): boolean
Get the state of a checkable action.
Parameters
| Name | Type | Description |
|---|---|---|
actionId | ChartActionId | An action ID. |
Returns
boolean — null if the action with specified id doesn't exist or is not checkable, true if the action is checked, false otherwise.
Example
if (widget.activeChart().getCheckableActionState("drawingToolbarAction")) {
// ...
};
getLineToolsState
getLineToolsState(): LineToolsAndGroupsState
Get the line tools state containing the drawings on the active chart.
This method requires that the saveload_separate_drawings_storage featureset is enabled.
Returns
getPanes
getPanes(): IPaneApi[]
Get an array of API objects for interacting with the chart panes.
Returns
IPaneApi[]
Example
widget.activeChart().getPanes()[1].moveTo(0);
getPriceToBarRatio
getPriceToBarRatio(): number
Get the chart's price to bar ratio.
Returns
number — The ratio or null if no ratio is defined.
Example
console.log(widget.activeChart().getPriceToBarRatio());
getSeries
getSeries(): ISeriesApi
Get the main series.
Returns
ISeriesApi — An API object for interacting with the main series.
Example
widget.activeChart().getSeries().setVisible(false);
getShapeById
getShapeById(entityId): ILineDataSourceApi
Get a drawing by ID.
Parameters
| Name | Type | Description |
|---|---|---|
entityId | EntityId | A drawing ID. |
Returns
ILineDataSourceApi — An API object for interacting with the drawing.
Example
widget.activeChart().getShapeById(id).bringToFront();
For more information, refer to Drawings API.
getStudyById
getStudyById(entityId): IStudyApi
Get a study by ID.
Parameters
| Name | Type | Description |
|---|---|---|
entityId | EntityId | The study ID. |
Returns
IStudyApi — An API object for interacting with the study.
Example
widget.activeChart().getStudyById(id).setVisible(false);
getTimeScale
getTimeScale(): ITimeScaleApi
Get an API object for interacting with the timescale.
Returns
Example
var time = widget.activeChart().getTimeScale().coordinateToTime(100);
getTimezoneApi
getTimezoneApi(): ITimezoneApi
Get an API object for interacting with the chart timezone.
Returns
getVisibleBarsRange
getVisibleBarsRange(): VisibleBarsTimeRange
Returns the range of bar times currently shown on the chart.
- This range includes existing bars and any visible incomplete bars created by non-time-based chart styles (for example, Renko).
- This range does not include future bar times beyond the last visible bar. To include them, use IChartWidgetApi.getVisibleRange instead.
Returns
getVisibleRange
getVisibleRange(): VisibleTimeRange
Get the current visible time range.
Returns
Example
console.log(widget.activeChart().getVisibleRange());
inactivityGaps
inactivityGaps(): IWatchedValue<boolean>
The visibility of inactivity gaps on intraday and DWM (daily, weekly, monthly) charts.
The inactivity_gaps featureset should be enabled to use this option.
When enabled (true), the chart displays gaps during trading sessions where there is missing data due to market inactivity.
Otherwise, these gaps are hidden and the chart appears continuous.
Returns
IWatchedValue<boolean>
isMaximized
isMaximized(): boolean
Check if the chart is maximized or not.
Returns
boolean — true if maximized, false otherwise.
isPriceToBarRatioLocked
isPriceToBarRatioLocked(): boolean
Get the locked/unlocked state of the chart's price to bar ratio.
Returns
boolean
Example
console.log(widget.activeChart().isPriceToBarRatioLocked());
isSelectBarRequested
isSelectBarRequested(): boolean
Check if bar selection mode is active or not.
Returns
boolean — true if active, false otherwise.
Example
var isRequested = widget.activeChart().isSelectBarRequested();
loadChartTemplate
loadChartTemplate(templateName): Promise<void>
Load and apply a chart template.
Parameters
| Name | Type | Description |
|---|---|---|
templateName | string | The name of the template to load. |
marketStatus
marketStatus(): IWatchedValueReadonly<MarketStatus>
Get a readonly watched value that can be used to read/subscribe to the state of the chart's market status.
Returns
IWatchedValueReadonly<MarketStatus>
maximizeChart
maximizeChart(): void
Maximize to its full size currently selected chart.
Returns
void
Example
widget.activeChart().maximizeChart();
onChartTypeChanged
onChartTypeChanged(): ISubscription<(chartType: SeriesType) => void>
Get a subscription object for the chart type changing.
Returns
ISubscription<(chartType: SeriesType) => void> — A subscription object for the chart type changing.
Example
widget.activeChart().onChartTypeChanged().subscribe(
null,
(chartType) => console.log('The type of chart is changed')
);
onDataLoaded
onDataLoaded(): ISubscription<() => void>
Get a subscription object for new data being loaded for the chart.
Returns
ISubscription<() => void> — A subscription object for new data loaded for the chart.
Example
widget.activeChart().onDataLoaded().subscribe(
null,
() => console.log('New history bars are loaded'),
true
);
onHoveredSourceChanged
onHoveredSourceChanged(): ISubscription<(sourceId: EntityId) => void>
Get a subscription object for the ID of the study or series hovered by the crosshair.
Returns
ISubscription<(sourceId: EntityId) => void> — A subscription object for the ID of the study or series hovered by the crosshair. Subscribers will be called with null if there is no study or series hovered.
onIntervalChanged
onIntervalChanged(): ISubscription<(interval: ResolutionString, timeFrameParameters: { timeframe?: TimeFrameValue }) => void>
Get a subscription object for the chart resolution (interval) changing. This method also allows you to track whether the chart's date range is changed.
The timeframe argument represents if a user clicks on the time frame toolbar or changes the date range manually.
If timeframe is undefined, you can change a date range before data loading starts.
To do this, you can specify a time frame value or a certain date range.
Returns
ISubscription<(interval: ResolutionString, timeFrameParameters: { timeframe?: TimeFrameValue }) => void> — A subscription object for the chart interval (resolution) changing.
Example
The following code sample specifies a time frame value:
widget.activeChart().onIntervalChanged().subscribe(null, (interval, timeframeObj) =>
timeframeObj.timeframe = {
value: "12M",
type: "period-back"
});
The following code sample specifies a certain date range:
widget.activeChart().onIntervalChanged().subscribe(null, (interval, timeframeObj) =>
timeframeObj.timeframe = {
from: new Date('2015-01-01').getTime() / 1000,
to: new Date('2017-01-01').getTime() / 1000,
type: "time-range"
});
onSymbolChanged
onSymbolChanged(): ISubscription<(symbol: LibrarySymbolInfo) => void>
Get a subscription object for the chart symbol changing.
Returns
ISubscription<(symbol: LibrarySymbolInfo) => void> — A subscription object for when a symbol is resolved (ie changing resolution, timeframe, currency, etc.)
Example
widget.activeChart().onSymbolChanged().subscribe(null, () => console.log('The symbol is changed'));
onVisibleRangeChanged
onVisibleRangeChanged(): ISubscription<(range: VisibleTimeRange) => void>
Get a subscription object for the chart's visible range changing.
Returns
ISubscription<(range: VisibleTimeRange) => void> — A subscription object for the chart's visible range changing.
Example
widget.activeChart().onVisibleRangeChanged().subscribe(
null,
({ from, to }) => console.log(from, to)
);
priceFormatter
priceFormatter(): INumberFormatter
Returns the object with 'format' function that you can use to format the prices.
widget.activeChart().priceFormatter().format(123);
Returns
refreshMarks
refreshMarks(): void
Force the chart to re-request all bar marks and timescale marks.
Returns
void
Example
widget.activeChart().refreshMarks();
reloadLineToolsFromServer
reloadLineToolsFromServer(): void
Manually trigger the chart to request the linetools again from the IExternalSaveLoadAdapter.loadLineToolsAndGroups method or the 'load_line_tools' endpoint of the Save and load REST API.
This method requires that the saveload_separate_drawings_storage featureset is enabled.
removeAllShapes
removeAllShapes(): void
Remove all drawings from the chart.
Returns
void
Example
widget.activeChart().removeAllShapes();
removeAllStudies
removeAllStudies(): void
Remove all studies from the chart.
Returns
void
Example
widget.activeChart().removeAllStudies();
removeEntity
removeEntity(entityId, options?): void
Remove an entity (e.g. drawing or study) from the chart.
Parameters
| Name | Type | Description |
|---|---|---|
entityId | EntityId | The ID of the entity. |
options? | UndoOptions | Optional undo options. |
Returns
void
Example
widget.activeChart().removeEntity(id);
requestSelectBar
requestSelectBar(): Promise<number>
Switch the chart to bar selection mode.
Returns
Promise<number> — A promise that resolves to the timestamp of a bar selected by the user. Rejects if the bar selection was already requested or is cancelled.
Example
widget.activeChart().requestSelectBar()
.then(function(time) {
console.log('user selects bar with time', time);
})
.catch(function() {
console.log('bar selection was rejected');
});
resetData
resetData(): void
Force the chart to re-request data, for example if there are internet connection issues. Before calling this function the IChartWidgetApi.resetCache method should be called.
Returns
void
Example
widget.activeChart().resetData();
resolution
resolution(): ResolutionString
Get the current resolution (interval).
Returns
Example
console.log(widget.activeChart().resolution());
restoreChart
restoreChart(): void
Restore to its initial size currently selected chart.
Returns
void
Example
widget.activeChart().restoreChart();
selection
selection(): ISelectionApi
Get an API object for interacting with the selection.
Returns
Example
widget.activeChart().selection().clear();
sendBackward
sendBackward(sources): void
Move the sources one level down in the Z-order.
Parameters
| Name | Type | Description |
|---|---|---|
sources | readonly EntityId[] | An array of source IDs. |
Returns
void
Example
widget.activeChart().sendBackward([id]);
sendToBack
sendToBack(entities): void
Move the group to the bottom of the Z-order.
Parameters
| Name | Type | Description |
|---|---|---|
entities | readonly EntityId[] | An array of entity IDs. |
Returns
void
Example
widget.activeChart().sendToBack([id]);
setAllPanesHeight
setAllPanesHeight(heights): void
Set the height for each pane in the order provided.
Parameters
| Name | Type | Description |
|---|---|---|
heights | readonly number[] | An array of heights. |
Returns
void
Example
console.log(widget.activeChart().setAllPanesHeight([250, 400, 200]));
setChartType
Recommended
setChartType(type): Promise<void>
Change the chart's type.
Parameters
| Name | Type | Description |
|---|---|---|
type | SeriesType | A chart type. |
Returns
Promise<void> — A promise that resolves when the chart type has changed and data has loaded.
Example
widget.activeChart().setChartType(12); // Specifies the High-low type
Throws
If the new chart type cannot load data. The error is created within the
library iframe, so an instanceof Error check in the embedding page will fail. Check the
name and message properties instead.
Deprecated
setChartType(type, callback): void
Use setChartType instead.
Change the chart's type.
Parameters
| Name | Type | Description |
|---|---|---|
type | SeriesType | A chart type. |
callback | () => void | An optional callback function. Called when the chart type has changed and data has loaded. |
Returns
void
Example
widget.activeChart().setChartType(12); // Specifies the High-low type
setDragExportEnabled
setDragExportEnabled(enabled): void
Enable or disable drag-to-export feature.
Parameters
| Name | Type | Description |
|---|---|---|
enabled | boolean | true to enable drag-to-export, false to disable. |
Returns
void
Example
// Enable drag-to-export, disable default chart drag to scroll
widget.activeChart().setDragExportEnabled(true);
widget.subscribe('dragstart', (params) => {
// create a HTML element for drag image
const dragImage = createDragImage();
// set drag image
params.setDragImage(dragImage, 0, 0);
const exportData = widget.activeChart().exportData();
// transform export data to csv
const csvData = transformExportDataToCsv(exportData);
params.setData('text/plain', csvData);
});
To implement drag-to-export, you need to handle the dragstart event in your application and set the data to the dataTransfer object.
setPriceToBarRatio
setPriceToBarRatio(ratio, options?): void
Set the chart's price to bar ratio.
Parameters
| Name | Type | Description |
|---|---|---|
ratio | number | The new price to bar ratio. |
options? | UndoOptions | Optional undo options. |
Returns
void
Example
widget.activeChart().setPriceToBarRatio(0.4567, { disableUndo: true });
setPriceToBarRatioLocked
setPriceToBarRatioLocked(value, options?): void
Lock or unlock the chart's price to bar ratio.
Parameters
| Name | Type | Description |
|---|---|---|
value | boolean | true to lock, false to unlock. |
options? | UndoOptions | Optional undo options. |
Returns
void
Example
widget.activeChart().setPriceToBarRatioLocked(true, { disableUndo: false });
setResolution
setResolution(resolution, options?): Promise<boolean>
Change the chart's interval (resolution).
Parameters
| Name | Type | Description |
|---|---|---|
resolution | ResolutionString | A resolution. |
options? | SetResolutionOptions | () => void | Optional object of options for the new resolution or optional callback that is called when the data for the new resolution has loaded. |
Returns
Promise<boolean> — A promise that resolves with a boolean value. It's true when the resolution has been set and false when setting the resolution is not possible.
Example
widget.activeChart().setResolution('2M');
Note: if you are attempting to change multiple charts (multi-chart layouts) at the same time with
multiple setResolution calls then you should set doNotActivateChart option to true.
setScrollEnabled
setScrollEnabled(enabled): void
Enable or disable scrolling of the chart.
Parameters
| Name | Type | Description |
|---|---|---|
enabled | boolean | true to enable scrolling, false to disable. |
Returns
void
Example
widget.activeChart().setScrollEnabled(false);
setSymbol
setSymbol(symbol, options?): Promise<boolean>
Change the chart's symbol.
Parameters
| Name | Type | Description |
|---|---|---|
symbol | string | A symbol. |
options? | SetSymbolOptions | () => void | Optional object of options for the new symbol or optional callback that is called when the data for the new symbol has loaded. |
Returns
Promise<boolean> — A promise that resolves with a boolean value. It's true when the symbol has been set and false when setting the symbol is not possible.
Example
widget.activeChart().setSymbol('IBM');
Note: if you are attempting to change multiple charts (multi-chart layouts) at the same time with
multiple setSymbol calls then you should set doNotActivateChart option to true.
setTimeFrame
setTimeFrame(timeFrame): void
Set the time frame for this chart.
Note: This action will set this chart as active in a multi-chart layout.
Parameters
| Name | Type | Description |
|---|---|---|
timeFrame | RangeOptions | Object specifying the range and resolution to be applied |
Returns
void
Example
To apply the '1Y' timeframe:
tvWidget.setTimeFrame({
val: { type: 'period-back', value: '12M' },
res: '1W',
});
setVisibleRange
setVisibleRange(range, options?): Promise<void>
Allows you to display a certain time range on the chart.
Parameters
| Name | Type | Description |
|---|---|---|
range | SetVisibleTimeRange | A range that will be made visible. |
options? | SetVisibleRangeOptions | Options for the new visible range. |
Returns
Promise<void> — A promise that resolves when the visible range is set.
Example
widget.activeChart().setVisibleRange(
{ from: 1420156800, to: 1451433600 },
{ percentRightMargin: 20 }
)
If the library cannot fit the specified range within the canvas, which may happen on small screens, it will ignore the from parameter. For more information, refer to the Time scale article.
setZoomEnabled
setZoomEnabled(enabled): void
Enable or disable zooming of the chart.
Parameters
| Name | Type | Description |
|---|---|---|
enabled | boolean | true to enable zooming, false to disable. |
Returns
void
Example
widget.activeChart().setZoomEnabled(false);
shapesGroupController
shapesGroupController(): IShapesGroupControllerApi
Get an API object for interacting with groups of drawings. Refer to the Drawings API article for more information.
Returns
Example
widget.activeChart().shapesGroupController().createGroupFromSelection();
showPropertiesDialog
showPropertiesDialog(studyId): void
Show the properties dialog for a study or drawing.
Parameters
| Name | Type | Description |
|---|---|---|
studyId | EntityId | An ID of the study or drawing. |
Returns
void
Example
const chart = widget.activeChart();
chart.showPropertiesDialog(chart.getAllShapes()[0].id);`
symbol
symbol(): string
Get the name of the current symbol.
Returns
string
Example
console.log(widget.activeChart().symbol());
symbolExt
symbolExt(): SymbolExt
Get an extended information object for the current symbol.
Returns
Example
console.log(widget.activeChart().symbolExt().name);
zoomOut
zoomOut(): void
Zoom out. The method has the same effect as clicking on the "zoom out" button.