Skip to main content

Interface: ISelectionApi

Charting Library.ISelectionApi

Allows you to select entities (drawings, indicators, and drawings groups) on the chart. Consider the following example:

var chart = tvWidget.activeChart();
// Prints all selection changes to the console
chart.selection().onChanged().subscribe(null, s => console.log(chart.selection().allItems()));
// Creates an indicator and saves its ID
var studyId = chart.createStudy("Moving Average", false, false, { length: 10 });
// Adds the indicator to the selection ([<id>] is printed to the console)
chart.selection().add(studyId);
// Clears the selection ([] is printed to the console)
chart.selection().clear();

Multiple Selection

Multiple selection has the following specifics:

  • Either indicators or drawings (including drawings groups) can be selected at the same time.
  • Drawings groups are multi-selectable and can coexist with symbol-bound drawings in the selection.
  • If you add an indicator to the selection, other entities are removed from it.
  • Adding an array of objects to the selection works the same as adding these objects one by one.

Methods

add

add(entities): void

Add entity / entities to selection. Accepts drawing/indicator ids as well as drawings-group ids.

Parameters

NameTypeDescription
entitiesSelectableItem | SelectableItem[]entities to be added to selection

Returns

void


allItems

allItems(): SelectableItem[]

Returns all selected entities — drawings, indicators, and drawings groups.

Returns

SelectableItem[]


allSources

allSources(): SelectableItem[]

Returns

SelectableItem[]

Deprecated

Use allItems instead.


canBeAddedToSelection

canBeAddedToSelection(entity): boolean

Whether the entity can be added to the selection. Accepts a drawing/indicator id or a drawings-group id.

Parameters

NameTypeDescription
entitySelectableItementity to be checked

Returns

boolean

true when entity can be added to the selection


clear

clear(): void

Clear selection

Returns

void


contains

contains(entity): boolean

Does the selection contain the entity. Accepts a drawing/indicator id or a drawings-group id.

Parameters

NameTypeDescription
entitySelectableItementity to be checked

Returns

boolean

true when entity is in the selection


isEmpty

isEmpty(): boolean

Is the selection empty

Returns

boolean

true when empty


onChanged

onChanged(): ISubscription<() => void>

Subscription for selection changes.

Returns

ISubscription<() => void>


remove

remove(entities): void

Remove entities from the selection. Accepts drawing/indicator ids as well as drawings-group ids.

Parameters

NameTypeDescription
entitiesSelectableItem | SelectableItem[]entities to be removed from the selection

Returns

void


set

set(entities): void

Set entity / entities as the selection. Accepts drawing/indicator ids as well as drawings-group ids.

Parameters

NameTypeDescription
entitiesSelectableItem | SelectableItem[]entities to be selected

Returns

void