Constructors

Accessors

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

  • Public: attach any primitive (indicators, profiles, custom overlays) to a pane.

    Parameters

    Returns void

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

    Parameters

    • opts: {
          crosshairMode?: CrosshairMode;
          grid?: { horzLines?: boolean; vertLines?: boolean };
          priceFormatter?: null | (price: number) => string;
          theme?: ChartTheme;
          timeFormatter?: (utcSeconds: number, tickMark?: TickMarkType) => string;
      }

    Returns void

  • Parameters

    • width: number
    • height: number

    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

  • 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

  • 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

  • Current grid line visibility.

    Returns { horzLines: boolean; vertLines: boolean }

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

    Returns void

  • 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, collapsing the others to a sliver. Calling it again (or on another pane) restores the previous weights.

    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

  • 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

  • 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

  • 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 default view: fit all bars on the time axis 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

  • Toggle the vertical (time) and/or horizontal (price) grid lines at runtime. Omitted fields keep their current visibility. Repaints every pane.

    Parameters

    • opts: { horzLines?: boolean; vertLines?: boolean }

    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

  • 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

  • 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

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