Skip to documentation content

Candlestick Chart

Plot open, high, low, and close prices per period, with optional volume and a zoom brush.

Daily share price

Overview

Use a candlestick chart to show how a price moved within each period: where it opened and closed, shown by the body, and how far it ranged, shown by the wick. Rising periods take the up color and falling periods the down color. It suits prices, exchange rates, and any measure with a meaningful open, high, low, and close.

When only the closing value matters, a line chart is easier to read.

Anatomy

CandlestickChart reads four fields per row (open, high, low, and close by default) and owns the category axis, zoom, and loading. Candles draws the bodies and wicks. Volume adds translucent volume bars along the bottom of the same plot, so they line up exactly with their candles; the price scale is lifted so the tallest volume bar never reaches the lowest wick. Add XAxis, YAxis, Grid, Tooltip, and Brush as needed.

The price axis sits on the right by default, as is usual for financial charts, and follows the zoomed window so the visible candles always fill the plot.

Accessibility

Up and down are encoded by color, which some readers cannot tell apart. The hollow variant adds a second cue: rising bodies are open and falling bodies are filled. The default ariaLabel reports the range, the first open, the last close, and the high and low, but readers who need individual periods need a nearby table. The crosshair, tooltip, and brush are pointer-operated.

Installation

npm install honestui

Usage

import { CandlestickChart, type ChartConfig } from "honestui/charts";
const chartConfig = {
  up: { label: "Up", colors: { light: ["#16a34a"], dark: ["#22c55e"] } },
  down: { label: "Down", colors: { light: ["#dc2626"], dark: ["#ef4444"] } },
} satisfies ChartConfig;

<CandlestickChart data={data} config={chartConfig} xDataKey="date">
  <CandlestickChart.Grid />
  <CandlestickChart.XAxis />
  <CandlestickChart.YAxis />
  <CandlestickChart.Tooltip />
  <CandlestickChart.Candles />
</CandlestickChart>

Rename the price fields with openDataKey, highDataKey, lowDataKey, and closeDataKey when your data uses other names. The tooltip lists the change with its percentage, then open, high, low, close, and volume. The crosshair labels both axes with the formatted date and price.

Examples

Volume and Brush

Volume and Brush

Pass volumeDataKey and add CandlestickChart.Volume to draw volume bars in the period's direction color. CandlestickChart.Brush adds a closing-price preview strip; dragging it zooms the candles and volume together. This example also uses the hollow variant.

Zoom and Reference Line

<CandlestickChart.Zoom />

CandlestickChart.Zoom zooms inside the plot: pinch, or scroll with Ctrl held, and drag to pan. The price axis refits to the visible candles, and a Reset zoom button appears while zoomed. It shares its window with the brush. A ReferenceLine marks a support or resistance level; see Brush and Zoom and Reference Lines.

Give the chart a syncId to move its crosshair with other charts over the same dates, such as a combo chart of trading activity below it.

Loading State

isLoading='true'

isLoading reserves the layout with neutral candles and the shared loading label.

API Reference

CandlestickChart
PropTypeDefaultDescription
data*TData[]–

One row per period, oldest first.

config*ChartConfig–

Labels and colors for up and down.

xDataKey*keyof TData & string–

The period field.

openDataKeykeyof TData & string"open"

Opening price field.

highDataKeykeyof TData & string"high"

High price field.

lowDataKeykeyof TData & string"low"

Low price field.

closeDataKeykeyof TData & string"close"

Closing price field.

volumeDataKeykeyof TData & string–

Volume field, drawn when Volume is present.

animationbooleantrue

Plays the intro animation. Series over 400 periods and reduced-motion preferences skip it.

isLoadingbooleanfalse

Shows neutral candles and the loading label.

syncIdstring–

Charts with the same id move their crosshair and tooltip together.

ariaLabelstring–

Accessible name for the canvas. A price summary is generated when omitted.

chartOptionsRecord<string, unknown>–

Escape hatch merged over the generated ECharts option.

Candles
PropTypeDefaultDescription
variantfilled|hollow"filled"

hollow leaves rising bodies open.

widthnumber0.6

Body width as a share of each period.

maxWidthnumber14

Widest a body may grow, in pixels.

Volume
PropTypeDefaultDescription
heightnumber0.2

Share of the plot height the tallest volume bar may reach.

YAxis
PropTypeDefaultDescription
positionleft|right"right"

Side of the price scale.

tickFormatter(value: number, index: number) => string–

Formats price labels.

labelstring–

Axis title.

hideDotsbooleanfalse

Hides the tick dots.

XAxis
PropTypeDefaultDescription
tickFormatter(value: string, index: number) => string–

Formats period labels and the crosshair's period label.

labelstring–

Axis title.

hideDotsbooleanfalse

Hides the tick dots.

Tooltip
PropTypeDefaultDescription
crosshairbooleantrue

Draws a dashed crosshair with labels on both axes. When false, only a vertical line is drawn.

valueFormatter(value: number) => string–

Formats prices in the tooltip and the crosshair label.

volumeFormatter(value: number) => string–

Formats volume. Defaults to compact notation.

labelFormatter(label: string) => string–

Formats the period shown as the tooltip title. Defaults to the XAxis tickFormatter.

variantdefault|frosted-glass"default"

Tooltip surface.

roundnesssm|md|lg|xl"lg"

Tooltip corner radius.

positionfixed|variable"variable"

Pins the tooltip to the top or lets it follow the pointer.

defaultIndexnumber–

Opens the tooltip at a period after mount.

Brush
PropTypeDefaultDescription
heightnumber56

Height of the preview strip in pixels.

formatLabel(value: string, index: number) => string–

Formats the range labels shown while the brush is hovered.

onChange(range: { startIndex: number; endIndex: number }) => void–

Fires when the selected range changes.

Zoom, ReferenceLine, ReferenceArea, ReferenceDot

CandlestickChart.Zoom takes the props listed in Brush and Zoom. The reference parts take the props listed in Reference Lines; a y value is a price.