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.
Options
Section titled “Options”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.
| Option | Type | Notes |
|---|---|---|
theme | Partial<ChartTheme> | Colors; DEFAULT_THEME is the base. |
crosshairMode | CrosshairMode | 'normal' or 'magnet' snapping. |
volumeVisible | boolean | Volume histogram in the main pane (default off). |
volumeHeightRatio | number | Fraction of plot height it occupies. |
priceLineVisible | boolean | Dotted last-close line + axis badge (default on). |
rightOffset | number | Blank bars kept to the right of the newest bar. |
priceAxisWidth / timeAxisHeight | number | px reserved for the axis strips. |
priceDecimals | number | Min decimals on price/crosshair labels (default 2). |
priceFormatter | (price, decimals) => string | Override price formatting (locale separators, …). |
dateFormatters | Partial<DateFormatters> | Localize axis/crosshair/clock text — see Localization. |
Methods
Section titled “Methods”Series
Section titled “Series”| Method | Returns | Notes |
|---|---|---|
addCandlestickSeries() | Series | Also addBar/Line/AreaSeries(). |
getSeries() | Series | null | The current series. |
The series type is only the starting renderer — series.setChartType(type)
switches it in place. See Series.
| Method | Returns | Notes |
|---|---|---|
setDataSource(source) | () => void | Attach a DataSource; returns teardown. |
fitContent() | void | Refit the viewport to the data. |
Indicators
Section titled “Indicators”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.
Instrument & coordinates
Section titled “Instrument & coordinates”| Method | Notes |
|---|---|
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). |
Viewport
Section titled “Viewport”| Method | Notes |
|---|---|
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. |
Extending
Section titled “Extending”| Method | Notes |
|---|---|
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. |
Events & lifecycle
Section titled “Events & lifecycle”const off = chart.on('crosshairMove', e => { /* … */})on(type, handler) subscribes and returns an unsubscribe function.
| Event | Payload | Fires when |
|---|---|---|
crosshairMove | CrosshairMoveEvent | null | The crosshair moved (or left). |
dataChange | SeriesChange | The series’ data or type changed. |
seriesChange | Series | A new series replaced the previous. |
indicatorsChange | void | An indicator was added/removed/shown/reconfigured. |
layoutChange | void | The chart resized or panes changed. |
instrumentChange | InstrumentInfo | null | The instrument was set. |
Call chart.remove() to destroy the instance and release its listeners.
Localization
Section titled “Localization”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.