Constructors

Accessors

  • get isDestroyed(): boolean
  • True once destroy() has run. Anything holding a chart it did not create (a link group, a controller, a host cache) needs to know the object is a corpse before it calls into it: inferring it from a side effect such as an empty pane list works only for as long as nothing else can empty one.

    Returns boolean

  • get rendererKind(): RenderBackendKind
  • The render backend the chart is painting series with right now: what the first pane was given, which is the renderer option unless its factory declined (no WebGL2 on this device) and the 2D backend stood in, and canvas2d from the moment a GPU backend degrades ('renderer:fallback').

    Returns RenderBackendKind

Methods

  • 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();

    Parameters

    • indicatorId: string
    • settings: Readonly<IndicatorSettings> = {}
    • options: { paneIndex?: number } = {}

    Returns IndicatorApi

  • Apply a subset of chart options at runtime (theme, grid, formatters, crosshair mode) without recreating the chart.

    Parameters

    Returns void

  • Parameters

    • width: number
    • height: number

    Returns void

  • Arm the next plot click to answer with a price or a bar time, handed to cb. Returns a cancel function; arming another pick on this chart cancels the pending one. pick:start and pick:end bracket it so a host can show its own cursor while the pick is live. See input/pick for why this does not touch placement mode.

    Parameters

    • kind: PickKind
    • cb: (value: number) => void

    Returns () => void

  • Map a container-relative media-px Y back to a price on a pane (inverse of priceToCoordinate).

    Parameters

    • y: number
    • paneIndex: number = 0

    Returns null | number

  • Container-relative x (media px) → UTC seconds.

    Parameters

    • x: number

    Returns number

  • Crosshair behaviour ('normal' or 'magnet'). Set it via applyOptions.

    Returns CrosshairMode

  • 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.

    Parameters

    • filename: string = 'chart.png'

    Returns void

  • The opaque drawings slot in the chart state. The base engine only round-trips it; the drawing tier reads and writes it.

    Returns unknown

  • Dispatch a named event. Public so the lazy trade layer can route through it.

    Parameters

    • event: string
    • payload: unknown

    Returns void

  • The chart as a standalone SVG document: every pane's base and overlay paint, in the order the DOM stacks them, run once into a serialising context at pixel ratio 1. Text stays text (selectable, searchable) and lines stay lines, so the file scales without the blur a PNG picks up.

    Nothing transient is in it: no crosshair, no hover state, no drag. What is in it is exactly what the renderers, primitives and drawing tools draw, because it is the same code drawing. A primitive that paints through a call with no vector form (a bitmap logo, a shadow) is simply thinner in the export; see SvgContext for the list.

    Returns the string only. Saving it is the host's job, the way downloadScreenshot is the host-facing half of takeScreenshot: new Blob([svg], { type: 'image/svg+xml' }) and an anchor is all it takes.

    Parameters

    Returns string

  • Fit all bars into view (no-arg convenience; bar count from the data).

    Returns void

  • 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.

    Returns ChartState & ChartSettingsState & { timezone: string }

  • Current grid options, visibility first (it is the one field always set).

    Returns { horzLines: boolean; vertLines: boolean } & Partial<GridOptions>

  • Whether the trade layer exists yet. Reading chart.trading creates one, and creating one claims the click/drag subscriptions, so anything that merely inspects the chart (a settings dialog) asks this first.

    Returns boolean

  • Call after a history-paging load resolves to re-enable the trigger.

    Returns void

  • Every live indicator instance, in the order they were added.

    Flushes any pending recompute first. Indicator maths is deferred to the frame, so a caller that updates a bar and reads a value back in the same turn would otherwise see the previous tick's numbers.

    Returns readonly IndicatorApi[]

  • Parameters

    • build: (mask: InvalidateMask) => void

    Returns void

  • The maximized pane index, or null when none is.

    Returns null | number

  • Expand one pane to fill the chart, hiding the others. Calling it again (or on another pane) puts the stack back exactly as it was, since the stored weights were never disturbed.

    Parameters

    • index: number

    Returns boolean

  • Move a pane up or down one slot. Pane 0 (price) is pinned — it owns the primary series and the shared price context — so a move that would displace it is refused.

    Parameters

    • index: number
    • direction: -1 | 1

    Returns boolean

  • Move a pane's price axis to the other strip, taking the series that map to it and everything the axis was set to. Returns false when that side carries nothing, or when the other side is already occupied: one strip draws one axis (see Pane.moveSeriesScale), which is what movable reports.

    Parameters

    • paneIndex: number
    • from: "left" | "right"
    • to: "left" | "right"

    Returns boolean

  • Remove one listener, or (when cb is omitted) every listener for an event.

    Parameters

    • event: string
    • Optionalcb: (payload: unknown) => void

    Returns void

  • Subscribe to a named chart event. Returns an unsubscribe function.

    Parameters

    • event: string
    • cb: (payload: unknown) => void

    Returns () => void

  • Subscribe to the next occurrence of an event, then auto-unsubscribe.

    Parameters

    • event: string
    • cb: (payload: unknown) => void

    Returns () => void

  • State of one price axis, for a host rendering a menu over it: what is currently on, and which items are worth offering. Null for a pane that does not exist.

    active false is a scale no series maps to: the ladder on an empty chart, or the side a menu was raised on before anything was plotted there. That is a row to render disabled with its state visible, not one to leave out.

    Parameters

    Returns null | PriceAxisState

  • 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.

    Parameters

    • price: number
    • paneIndex: number = 0

    Returns null | number

  • The primary price series: the first one added, and the one the magnet crosshair, the OHLC legend, the market-replay controller and a settings dialog's Symbol tab all describe. Null until a price series exists.

    Returns null | SeriesApi

  • Type and live style of the primary series, for a settings dialog: the type decides which controls apply (a candle has borders, a line has a dash), and the style is the object applyOptions patches.

    Returns null | { style: Readonly<SeriesStyle>; type: SeriesType }

  • Remove one indicator instance by its handle id. Returns true if it existed.

    Parameters

    • instanceId: string

    Returns boolean

  • 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.

    Parameters

    • index: number

    Returns boolean

  • Restore the preferred visible bar count and re-enable auto-scaling on every price axis (undoing any pan/zoom or manual axis drag). Same as double-clicking the chart.

    Returns void

  • 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.

    Parameters

    • state: unknown

    Returns RestoreReport

  • Put every pane's price axis back under autoscale, or pin it where it is. PriceScale.setAutoScale alone changes nothing on screen until something else asks for a frame; this re-measures and repaints.

    Parameters

    • on: boolean

    Returns void

  • The Canvas option block (grid, crosshair, scale text/lines, plot margins). Each sub-block merges field by field, so setting one grid colour leaves the rest of the grid alone.

    Parameters

    Returns void

  • Hand the chart the corporate-action / news calendar and let it own the strip. The difference from addEventMarkers is who filters: holding the full list here is what lets setEventOptions (the settings dialog's Events switches) turn a type off and back on without the host re-supplying data.

    Parameters

    • events: readonly ChartEvent[]
    • paneIndex: number = 0

    Returns void

  • Grid lines at runtime: visibility of each axis, plus its colour, dash, width and spacing. Omitted fields keep their current value. Repaints every pane.

    Parameters

    Returns void

  • Register a callback fired when the user pans near the left (oldest) edge.

    Parameters

    • loader: () => void

    Returns void

  • Set a pane's relative height weight. Panes share the chart height in proportion to their weights, so only the ratio matters.

    Parameters

    • index: number
    • weight: number

    Returns void

  • 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.

    Parameters

    • active: boolean

    Returns void

  • Auto-fit one axis: its range tracks the data again, or stays where the user left it. Turning it on releases any ratio lock on that axis, for the reason given in setAutoScale.

    Parameters

    Returns void

  • Pin one axis' price-per-bar ratio: zooming the time axis then rescales the prices with it, so a trend drawn at 45 degrees stays at 45 degrees. The axis goes manual, because auto-fit would re-fit the data every frame and undo the ratio being held.

    Returns whether the axis is now in the state asked for. Locking fails on a scale nothing has measured: there is no ratio to hold on an empty pane, or on one whose series plot no values at all.

    Parameters

    Returns boolean

  • Options for one pane's scale (mode, invert, tick size, margins) rather than every pane's. The four modes are one field, so picking one drops the previous by construction: a menu renders them as a single choice.

    Parameters

    Returns void

  • 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.

    Parameters

    • fn: null | (price: number) => string

    Returns void

  • Price-scale options for every pane (mode, inverted, tick size, margins), and the default new panes inherit.

    scope says how far a chart-wide setting reaches:

    • 'primary' (default): each pane's right scale only. A mode change wants this: rebasing a volume overlay quotes percent change in lots.
    • 'axes': every scale that draws a ladder, so the left axis moves with the right. Plot margins want this.
    • 'all': the hidden overlay scales too. Almost nothing should: an overlay's margins are its creator's placement, see Pane.axisScales.

    minMove is the one field no scope carries onto a pane that does not quote the instrument, whichever scope is asked for: see _scalePatchFor. Every other field is a property of the axis and reaches exactly as far as scope says.

    Parameters

    Returns void

  • Per-field status-line switches, applied to every pane legend on the chart: the host's symbol row and the indicator rows alike, which is what makes one switch mean the same thing everywhere. Merges field by field.

    Parameters

    Returns void

  • Set a custom time-axis + crosshair label formatter (UTC seconds -> string) at runtime. Pass undefined to restore the IST default.

    Parameters

    • fn: undefined | (utcSeconds: number, tickMark?: TickMarkType) => string

    Returns void

  • Change the zone the time axis and crosshair label in, without rebuilding the chart: a terminal switching from an NSE symbol to a US one needs exactly this. Throws on a name the runtime does not recognise, rather than quietly labelling in the old zone, because a chart showing the wrong hours is the kind of wrong nobody notices until it costs money.

    Parameters

    • zone: string

    Returns void

  • Subscribe to clicks on hit-testable primitives (markers, events, lines).

    Parameters

    • cb: (externalId: string) => void

    Returns void

  • 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.

    Parameters

    Returns void

  • 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.

    Parameters

    • onDrag: (externalId: string, price: number, time: number) => void
    • OptionalonDragEnd: (externalId: string, price: number, time: number) => void

    Returns void

  • Flatten 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.

    Returns HTMLCanvasElement

  • UTC seconds → container-relative x (media px). The inverse of _xToTime.

    Parameters

    • time: number

    Returns number

  • A host for the (lazy-loaded) trade layer to attach/detach its primitives on a pane.

    Parameters

    • paneIndex: number = 0

    Returns { addPrimitive(p: IPrimitive): void; removePrimitive(p: IPrimitive): void }

  • Trade-layer colours, whether or not the controller has been created. Once it exists it is the single answer (a host may set colours on it directly); before that, the held patch is folded onto the defaults. The fold is needed because the two shapes name a colour differently: the patch says longColor, the resolved palette says long.

    Returns TradingColors