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:
- Easy persistence: serialize state to JSON.
- Straightforward undo/redo: immutable state changes are easy to track.
- 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.optionscontrol 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.maindefaults totrue;strip.annotationsdefaults tofalse.getDefaultTemplate()returns the default template used during feed initialization.print(options)prints the chart as currently rendered.options.titleuses the same shape assetTitle.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 }wheredatais a PNG data URI.optionscan override width/height and passtitle.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 isYYYY-MM-DD HH:mm:ss(YYYY-MM-DDfor EOD).getDataStats()returns{ dataRange: { from, to }, barCount }wherefrom/toare UNIX timestamps in milliseconds.
Title object
The title object (used by setTitle, print, and exportImage) has these properties:
text: text to renderalign:left|right|centerverticalAlign:top|bottom|middlex,y: pixel coordinates relative to chart viewportstyle:{ 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 id | Summary | Details |
|---|---|---|
MainPlot (Symbol deprecated) | Changes the primary plot source | MainPlot |
Aggregation | Merges aggregation values | Aggregation |
Period | Sets duration or explicit date range | Period |
Crosshair | Enables/disables and styles crosshair lines | Crosshair |
Tooltip | Controls tooltip visibility and mode | Tooltip |
Events | Toggles dividends/earnings/splits markers | Events |
Scale | Sets scale mode and axis-related options | Scale |
Other | Applies miscellaneous chart options | Other |
Plot | Adds/reads/removes/updates plots | Plot |
Compare | Configures comparison plots | Compare |
Annotation | Removes/updates/duplicates annotations | Annotation |
Theme | Updates key chart theme values | Theme |
Clear | Clears annotations/studies by pane or globally | Clear |
Previous | Reads or updates previous-value line settings | Previous |
MovePlot | Moves a plot between panes | MovePlot |
PinPlot | Moves a plot between axes, including detached/no-axis mode | PinPlot |