Indicators & Overlays
Indicators (MA, VOL, RSI, …) and overlays (drawing tools like price lines, segments, …) are managed as declarative children of <KLineChart>. Each manages its own lifecycle: create on mount, remove on unmount, override on change.
Indicators
Section titled “Indicators”Use <KLineChart.Indicator> or the useIndicator() hook.
<KLineChart data={data}> {/* By name */} <KLineChart.Indicator value="VOL" />
{/* By config object */} <KLineChart.Indicator value={{ name: "MA", calcParams: [5, 10, 30] }} />
{/* In its own pane with custom options */} <KLineChart.Indicator value="MACD" pane={{ height: 120 }} />
{/* Stacked onto an existing pane */} <KLineChart.Indicator value={{ name: "EMA", calcParams: [20] }} isStack /></KLineChart>| Prop | Type | Description |
|---|---|---|
value |
string | IndicatorCreate |
Indicator name or full config. |
isStack |
boolean |
Stack onto existing indicators in the same pane. |
pane |
Partial<PaneOptions> |
Options applied to the indicator pane via setPaneOptions (e.g. height). |
yAxis |
YAxisOverride |
Y axis config for the indicator’s pane, applied via overrideYAxis. |
paneOptions |
Partial<PaneOptions> |
Deprecated. Alias for pane. |
How it maps to KlineCharts v10
Section titled “How it maps to KlineCharts v10”In KlineCharts v10, createIndicator(value, isStack) no longer accepts a separate options object — paneId/yAxisId live on the IndicatorCreate value itself. The hook therefore:
- Creates the indicator, capturing its id (
useIndicatorreturns the indicator id). - Applies
paneto the resulting pane viasetPaneOptions({ id: paneId, ...pane }). - Configures the pane’s Y axis via
overrideYAxiswhenyAxisis provided (createIndicatoralready creates an axis, socreateYAxiswould be a no-op).
Overlays
Section titled “Overlays”Use <KLineChart.Overlay> or the useOverlay() hook.
<KLineChart data={data}> {/* Built-in drawing tool by name */} <KLineChart.Overlay value="priceLine" />
{/* With points */} <KLineChart.Overlay value={{ name: "priceSegment", points: [ { timestamp: 1680000000000, value: 28000 }, { timestamp: 1680086400000, value: 29000 }, ], }} />
{/* Batch creation */} <KLineChart.Overlay value={["priceLine", "priceLine"]} /></KLineChart>| Prop | Type | Description |
|---|---|---|
value |
string | OverlayCreate | Array<...> |
Overlay name, config, or batch array. |
useOverlay returns the overlay id (or an array of ids for batch creation).
Custom indicators & overlays
Section titled “Custom indicators & overlays”Register custom indicators/overlays at the module level (re-exported from KlineCharts):
import { registerIndicator, registerOverlay } from "react-klinecharts";
registerIndicator({ name: "MyIndicator", calc: (dataList) => dataList.map((d) => ({ value: d.close })), figures: [{ key: "value", title: "VAL: ", type: "line" }],});
// Then use it like any built-in:<KLineChart.Indicator value="MyIndicator" />See the Registration Functions reference for the full list.