Skip to content

Chart

import { createChart } from '@lightfin/core'
const chart = createChart(container, options)

createChart(container, options?) creates a chart that fills container and observes it for resizes. Returns a Chart.

Passed once at creation (ChartOptionsInput — every field optional; theme and dateFormatters are deep-partial). The engine has no live option setter; to change options, re-create the chart.

OptionTypeNotes
themePartial<ChartTheme>Colors; DEFAULT_THEME is the base.
crosshairModeCrosshairMode'normal' or 'magnet' snapping.
volumeVisiblebooleanVolume histogram in the main pane (default off).
volumeHeightRationumberFraction of plot height it occupies.
priceLineVisiblebooleanDotted last-close line + axis badge (default on).
rightOffsetnumberBlank bars kept to the right of the newest bar.
priceAxisWidth / timeAxisHeightnumberpx reserved for the axis strips.
priceDecimalsnumberMin decimals on price/crosshair labels (default 2).
priceFormatter(price, decimals) => stringOverride price formatting (locale separators, …).
dateFormattersPartial<DateFormatters>Localize axis/crosshair/clock text — see Localization.
MethodReturnsNotes
addCandlestickSeries()SeriesAlso addBar/Line/AreaSeries().
getSeries()Series | nullThe current series.

The series type is only the starting renderer — series.setChartType(type) switches it in place. See Series.

MethodReturnsNotes
setDataSource(source)() => voidAttach a DataSource; returns teardown.
fitContent()voidRefit the viewport to the data.
const sma = await chart.addIndicator(
import('@lightfin/core/indicators/sma'),
{ period: 20 },
)

addIndicator(source, options?) loads an indicator (pass a dynamic import() so its code only ships when used) and returns an IndicatorHandle; chart.indicators() lists them. Sixteen indicators ship — see the full Indicators reference for the catalog, the handle, and how to write your own.

MethodNotes
setInstrument(info) / instrument()Symbol, precision, timezone (powers the chrome).
timeToCoordinate(t)Time → x pixel (or null if off-screen).
coordinateToTime(x, snap?)x pixel → time.
priceToCoordinate(p) / coordinateToPrice(y)Price ↔ y pixel.
formatPrice(price)Format using the instrument’s precision.
paneLayout() / plotRect()Current pane rectangles (for overlays).
MethodNotes
visibleTimeRange()The { from, to } currently in view, or null.
setVisibleTimeRange(range)Scroll/zoom to a time range (async).
scrollToTime(time)Bring a time into view (async).
crosshairMode() / setCrosshairMode(mode)Read/switch magnet snapping.
MethodNotes
onOrderIntent(handler)Opt into the ”+” order button; fires with price/coordinate.
attachPrimitive(primitive)Low-level canvas hook — the basis for price lines and event tags.
const off = chart.on('crosshairMove', e => {
/* … */
})

on(type, handler) subscribes and returns an unsubscribe function.

EventPayloadFires when
crosshairMoveCrosshairMoveEvent | nullThe crosshair moved (or left).
dataChangeSeriesChangeThe series’ data or type changed.
seriesChangeSeriesA new series replaced the previous.
indicatorsChangevoidAn indicator was added/removed/shown/reconfigured.
layoutChangevoidThe chart resized or panes changed.
instrumentChangeInstrumentInfo | nullThe instrument was set.

Call chart.remove() to destroy the instance and release its listeners.

dateFormatters localizes every piece of date/time text — axis tick labels, the crosshair’s time box, and the exchange clock. Override any subset of DEFAULT_DATE_FORMATTERS (English month names, 24-hour clock):

const fmt = (opts: Intl.DateTimeFormatOptions) =>
new Intl.DateTimeFormat('de-DE', { ...opts, timeZone: 'UTC' })
createChart(container, {
dateFormatters: {
month: d => fmt({ month: 'short' }).format(d),
monthDay: d => fmt({ month: 'short', day: 'numeric' }).format(d),
},
})

Each callback receives a wall-clock-as-UTC Date — read its getUTC* fields (or format with timeZone: 'UTC'), never the local-time getters. Price text localizes separately via priceFormatter / priceDecimals.