Skip to main content
Version: v26

ISelectionApi

Interface

Allows you to select entities (drawings and indicators) 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().allSources()));
// 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 can be selected at the same time.
  • 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 entity / entities to selection

Signature

add(entities: EntityId | EntityId[]) => void

Parameters

NameTypeDescription
entitiesEntityId | EntityId[]entities to be added to selection

Returns

void


allSources

Returns all the entities in the selection

Signature

allSources() => EntityId[]

Returns

EntityId[]


canBeAddedToSelection

Whether the entity can be added to the selection

Signature

canBeAddedToSelection(entity: EntityId) => boolean

Parameters

NameTypeDescription
entityEntityIdentity to be checked

Returns

true when entity can be added to the selection

boolean


clear

Clear selection

Signature

clear() => void

Returns

void


contains

Does the selection contain the entity

Signature

contains(entity: EntityId) => boolean

Parameters

NameTypeDescription
entityEntityIdentity to be checked

Returns

true when entity is in the selection

boolean


isEmpty

Is the selection empty

Signature

isEmpty() => boolean

Returns

true when empty

boolean


onChanged

Subscription for selection changes.

Signature

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

Returns

ISubscription<() => void>


remove

Remove entities from the selection

Signature

remove(entities: EntityId[]) => void

Parameters

NameTypeDescription
entitiesEntityId[]entities to be removed from the selection

Returns

void


set

Set entity / entities as the selection

Signature

set(entities: EntityId | EntityId[]) => void

Parameters

NameTypeDescription
entitiesEntityId | EntityId[]entities to be selected

Returns

void