The data-driven trading layer: push positions/orders/trades and the chart
renders pills + markers, emitting trading:* events on interaction. Created
on first access.
Add an earnings/dividend/split event-marker strip to a pane.
Add a registered indicator. Built-in descriptors live in the lazy
openalgo-charts/indicators tier — import it (or register your own with
registerIndicator) before calling this.
'onchart' indicators overlay the price pane; 'pane' indicators get a new
pane of their own unless paneIndex says otherwise. The returned handle
recomputes automatically whenever the source data changes.
import 'openalgo-charts/indicators';
const macd = chart.addIndicator('macd', { fastPeriod: 8 });
macd.setSettings({ fastPeriod: 12 });
macd.remove();
Add a horizontal price line (order/SL/TP/alert/level) to a pane.
Public: attach any primitive (indicators, profiles, custom overlays) to a pane.
Add a series and return its data handle.
Apply a subset of chart options at runtime (theme, grid, formatters, crosshair mode) without recreating the chart.
Composite the full chart (all panes + overlays) and trigger a PNG download. This is what the screenshot keyboard shortcut runs; call it from a toolbar button for a reliable "save image" — the browser's native right-click "Save image as…" captures only the topmost (transparent overlay) canvas.
Capture the chart's serialisable state: viewport, grid, crosshair mode,
pane weights and price scales, indicator instances, and a drawings slot
the drawing tier fills. JSON-safe.
Series data is not captured — the app owns that (it knows the symbol, the timeframe, and the feed). Series descriptors are, so an app that rebuilds its own series can re-apply their styling and placement.
The current visible logical range.
Every live indicator instance, in the order they were added.
Map a price to a container-relative Y in media (CSS) px, for positioning DOM
overlays (order panels, tooltips) over a pane. Returns null if the pane
doesn't exist. The inverse is coordinateToPrice.
Remove a pane, everything drawn in it, and any indicator that lives there. Pane 0 (price) is never removable — removing it would leave the chart with no time axis owner.
Returns false when the index is out of range or is pane 0.
Remove a primitive from whichever pane holds it.
Re-apply a state captured by getState. Restores grid, crosshair mode,
pane weights and price scales, indicators, and the viewport — everything
the chart is the source of truth for.
It does not recreate series: the chart has no way to know their data.
The returned report lists the series descriptors it saw so the caller can
rebuild them (addSeries(s.type, { paneIndex: s.paneIndex, style: s.style }))
and then feed them.
Restore the viewport after your data lands — logical ranges index bars, so
a range applied to an empty chart means nothing. Call restoreState again
(or setVisibleLogicalRange) once the series are populated.
Turn pointer gestures into anchor placement instead of panning. A host arms
this while a drawing tool is active: a press no longer scrolls the chart, and
a press-drag-release is reported as two click events (press point, then
release point, the latter tagged viaDrag) so a two-point shape can be drawn
in one gesture. DrawingController drives this for you.
Set a custom price formatter for every pane's axis labels, last-price tag, and price-line labels at runtime (e.g. switch to a currency format). Pass null to restore the default tick-size-aware formatting.
Swap the palette at runtime (dark/light toggle) without recreating the chart.
Set a custom time-axis + crosshair label formatter (UTC seconds -> string) at runtime. Pass undefined to restore the IST default.
Restore a saved logical range (e.g. preserve the user's zoom across a data reload).
Subscribe to crosshair movement for an OHLC legend / tooltip. The callback fires with the hovered bar of the primary price series on every move, and with all-null fields when the pointer leaves the plot.
Subscribe to drags of draggable primitives (order / SL / TP lines, drawing handles). Fires per move and on release.
time is the UTC seconds under the cursor, interpolated between bars and
extrapolated past the right edge — so a two-axis drag (a trendline endpoint,
a projection) has a usable time even where the gapless axis has no bar.
Price-only consumers can simply ignore it.
OptionalonDragEnd: (externalId: string, price: number, time: number) => voidFlatten every pane's base + overlay canvas into one opaque canvas (device px). The chart renders as stacked layered canvases, so the browser's native right-click "Save image" only captures the layer under the pointer (usually the transparent crosshair overlay) — use this to export the full chart.
A host for the (lazy-loaded) trade layer to attach/detach its primitives on a pane.
The keyboard shortcut manager (null when shortcuts are disabled).