Skip to content

Main API

This page documents the chart accessor used by chart consumers.

The accessor updates an immutable chart state object (the chart definition) and lets the presenter initialize itself from that state. That gives us:

  1. Easy persistence: serialize state to JSON.
  2. Straightforward undo/redo: immutable state changes are easy to track.
  3. Easy restore: saved chart state can be loaded back directly.

The chart state is a single JavaScript object we call a definition. It is formally described by schema and explained in Chart state.

Accessor methods

Below is a summary of accessor methods (namespace omitted for readability):

  • load(definition, options) loads saved definition JSON. options control merge behavior for annotations and comparison plots. Default: { keepOldAnnotations: false, keepNewAnnotations: true, keepOldCompare: false, keepNewCompare: true }. By default, existing annotations/comparison plots are discarded and incoming ones are kept. Annotation merge logic matches panes by standalone study id. Comparison merge logic de-duplicates old symbols first, enforces max-compare count (4), then maps plots to matching axes.
  • save() returns current state as JSON string.
  • asTemplate(strip) converts current definition to a reusable template. strip.main defaults to true; strip.annotations defaults to false.
  • getDefaultTemplate() returns the default template used during feed initialization.
  • print(options) prints the chart as currently rendered. options.title uses the same shape as setTitle.
  • setTitle(title) sets a runtime chart title. This title currently does not persist with saved state.
  • reset() resets chart state to the first definition loaded after initialization.
  • exportImage(options) returns { width, height, data } where data is a PNG data URI. options can override width/height and pass title.
  • annotate(id, traits = null, data = null) creates annotations; details are on Annotations.
  • change(...actions) applies one or more chart actions in one batch.
  • exportData() exports main plot and loaded study data as CSV. Numbers use . as decimal separator; datetime format is YYYY-MM-DD HH:mm:ss (YYYY-MM-DD for EOD).
  • getDataStats() returns { dataRange: { from, to }, barCount } where from/to are UNIX timestamps in milliseconds.

Title object

The title object (used by setTitle, print, and exportImage) has these properties:

  • text: text to render
  • align: left | right | center
  • verticalAlign: top | bottom | middle
  • x, y: pixel coordinates relative to chart viewport
  • style: { fontSize, color }

Change action reference

The change(...actions) API accepts action objects by id. Each action now has a dedicated page under API action details.

Action idSummaryDetails
MainPlot (Symbol deprecated)Changes the primary plot sourceMainPlot
AggregationMerges aggregation valuesAggregation
PeriodSets duration or explicit date rangePeriod
CrosshairEnables/disables and styles crosshair linesCrosshair
TooltipControls tooltip visibility and modeTooltip
EventsToggles dividends/earnings/splits markersEvents
ScaleSets scale mode and axis-related optionsScale
OtherApplies miscellaneous chart optionsOther
PlotAdds/reads/removes/updates plotsPlot
CompareConfigures comparison plotsCompare
AnnotationRemoves/updates/duplicates annotationsAnnotation
ThemeUpdates key chart theme valuesTheme
ClearClears annotations/studies by pane or globallyClear
PreviousReads or updates previous-value line settingsPrevious
MovePlotMoves a plot between panesMovePlot
PinPlotMoves a plot between axes, including detached/no-axis modePinPlot