Search documentation

Search pages, components, blocks, styles and colours.

Get started
Skip to content

Candlestick Chart

PreviousNext

Open, high, low and close per period, with optional volume and a line at the latest close.

ACME
Acme Inc, daily prices in November
ACME daily prices in November
OpenHighLowCloseVolumeChange
Nov 2$182.60$184.65$180.84$182.453.4M–
Nov 3$182.50$184.00$179.04$181.124.8M-0.73%
Nov 4$180.62$185.29$179.88$183.504.5M+1.31%
Nov 5$183.50$186.49$183.49$185.024.8M+0.83%
Nov 6$185.69$187.11$182.68$182.764.8M-1.22%
Nov 9$181.88$183.76$178.62$179.893.7M-1.57%
Nov 10$179.24$183.02$177.30$181.854.8M+1.09%
Nov 11$181.75$181.87$177.38$178.725.8M-1.72%
Nov 12$178.21$179.94$177.48$179.445.5M+0.40%
Nov 13$180.16$180.92$179.48$180.433.8M+0.55%
Nov 16$179.58$182.54$177.92$180.916.1M+0.27%
Nov 17$180.09$184.44$177.83$183.414.5M+1.38%
Nov 18$182.63$183.50$178.29$179.455.9M-2.16%
Nov 19$180.25$181.98$175.26$177.504.7M-1.09%
Nov 20$177.91$179.16$173.91$175.884M-0.91%
Nov 23$176.87$179.72$175.83$177.524.8M+0.93%
Nov 24$177.19$178.85$175.44$178.074M+0.31%
Nov 25$177.97$182.25$175.58$180.586.5M+1.41%
Nov 27$180.44$181.68$180.20$180.975.1M+0.22%
Nov 30$180.60$184.98$180.38$182.815.1M+1.02%

Give it rows with open, high, low and close fields, and optionally volume, plus the field that names each period (index). Each period is a candle: a body from the open to the close and a 1px wick from the low to the high. A period that closed at or above its open is drawn in the success colour, one that closed below in the destructive colour. Bodies are at most 12px wide, and the price scale fits the prices instead of starting at zero.

When the data has volume, it runs along the bottom as bars in each candle's colour, faint, in a band about a fifth of the plot's height. A dashed hairline crosses the plot at the latest close, with the price in a pill at its end. Point at a candle, drag a finger across the chart or tab to it and use the arrow keys: a crosshair finds the period and a tooltip gives its open, high, low, close, volume and the change from the previous close as a signed percentage.

Candlestick Chart is part of the Fabricator style. It's drawn in SVG, so the same component ships for every base, and its layout comes from the same model as the React Native version.

Installation

bunx --bun fabricator-ui@latest add candlestick-chart

Usage

import { CandlestickChart } from "@/components/ui/candlestick-chart"
const data = [
  { day: "Nov 2", open: 182.6, high: 184.65, low: 180.84, close: 182.45, volume: 3_384_000 },
  { day: "Nov 3", open: 182.5, high: 184.0, low: 179.04, close: 181.12, volume: 4_769_000 },
  { day: "Nov 4", open: 180.62, high: 185.29, low: 179.88, close: 183.5, volume: 4_544_000 },
]
 
<CandlestickChart data={data} index="day" label="ACME daily prices" />

A period missing any of its four prices keeps its place along the bottom and draws no candle. formatValue receives the field as its key (open, high, low, close or volume), so prices and volume can be written differently. By default prices take two decimals and volume is compact (4.8M). The chart fills its container's width and is 18rem tall until you give it a height with className.

Examples

Live data

Candles are matched by their index value, so when a period is added and the oldest one dropped, the candles slide along instead of redrawing. The new one grows from its open, and the last-close line follows it.

ACME price by minute
OpenHighLowCloseVolumeChange
09:30182.40182.99182.04182.87302K–
09:31182.87183.12182.16182.5793K-0.16%
09:32182.57183.34182.17182.80241K+0.13%
09:33182.80183.49182.45183.11289K+0.17%
09:34183.11183.81182.53183.60125K+0.27%
09:35183.60184.09182.88182.89152K-0.39%
09:36182.89184.10182.72183.59190K+0.38%
09:37183.59184.53183.24184.18185K+0.32%
09:38184.18184.85183.90184.55300K+0.20%
09:39184.55184.81183.58183.81139K-0.40%
09:40183.81184.39183.65184.35131K+0.29%
09:41184.35184.69183.46183.84206K-0.28%
09:42183.84184.15183.60183.82224K-0.01%
09:43183.82184.90183.50184.55145K+0.40%
09:44184.55185.14183.81184.0288K-0.29%
09:45184.02184.14183.54183.85267K-0.09%
09:46183.85184.70183.80184.63318K+0.42%
09:47184.63185.10184.01184.58120K-0.03%
09:48184.58185.62184.18185.40174K+0.44%
09:49185.40185.83185.01185.4686K+0.03%
09:50185.46186.16184.97186.00156K+0.29%
09:51186.00186.79185.54186.43307K+0.23%
09:52186.43186.93185.79186.30189K-0.07%
09:53186.30186.78185.33185.78118K-0.28%
09:54185.78186.37185.35185.40103K-0.20%
09:55185.40186.68185.07186.23138K+0.45%
09:56186.23186.59185.32185.52174K-0.38%
09:57185.52185.97185.01185.1482K-0.20%
09:58185.14186.00184.69185.82106K+0.37%
09:59185.82186.66185.50186.52223K+0.38%

Without volume

Data without a volume field draws no volume band; volume={false} leaves it out when the data has one. legend adds a key naming the up and down colours.

  • Up
  • Down
ACME weekly prices
OpenHighLowCloseChange
Sep 7171.20176.40169.80175.10–
Sep 14175.10178.90172.30173.00-1.20%
Sep 21173.00174.20166.50167.90-2.95%
Sep 28167.90172.80165.10171.60+2.20%
Oct 5171.60179.50170.90178.80+4.20%
Oct 12178.80183.20176.40181.70+1.62%
Oct 19181.70182.60175.30176.20-3.03%
Oct 26176.20181.00174.80180.30+2.33%
Nov 2180.30187.10179.00182.80+1.39%
Nov 9182.80183.80177.30180.40-1.31%
Nov 16180.40184.40173.90175.90-2.49%
Nov 23175.90185.00175.40182.80+3.92%

Colours

Rising periods take success and falling ones destructive, the status roles, so they follow the theme in light and dark. The tooltip always writes the change with its sign, so the direction never rests on colour alone. Give either direction its own name or colour with config:

<CandlestickChart
  data={data}
  index="day"
  label="ACME daily prices"
  config={{
    up: { label: "Gain", color: "chart-series-1" },
    down: { label: "Loss", color: "chart-series-2" },
  }}
/>

Volume bars take their candle's colour at 30% opacity. The last-close line is a muted hairline and its pill is drawn in the foreground colour, the strongest contrast in either mode.

Motion

  • Grow: the first time the chart scrolls into view, each body grows from its open toward its close in a quick wave along the periods, its wick and volume with it, on the reveal role, once per mount.
  • Slide: when data changes, candles that stay move to their new place and size on the move role. A new candle grows from its open as it slides in from the end; one that left the data shrinks as it slides out the other way.
  • Glide: the crosshair and the tooltip glide between periods on the glide role.

All three follow the motion speed of the region they sit in. Reduce Motion and the instant speed draw the chart at once and drop the glide; animate={false} does the same for one chart.

API Reference

CandlestickChart

All other props go to the root <div>.

PropTypeDefault
dataTDatum[]required
indexkeyof TDatumrequired
labelstringrequired: the accessible name
configCandlestickConfigUp in success, Down in destructive
volumebooleanon when the data has volume
formatValue(value: number, key: string) => string1,234.50, volume 4.8M
formatIndex(value: string, datum: TDatum) => stringthe field as text
legendbooleanfalse
tooltipbooleantrue
animatebooleantrue
loadingbooleanfalse
emptyReactNode"No data"
onActiveChange(active: ChartActive<TDatum> | null) => void-

CandlestickConfig

FieldTypeDefault
up{ label?: string; color?: ChartColor }{ label: "Up", color: "success" }
down{ label?: string; color?: ChartColor }{ label: "Down", color: "destructive" }

Data attributes

AttributeElementPresent when
data-slot="candlestick-chart"rootalways
data-loadingrootloading is true
data-slot="chart-plot"the plotalways
data-slot="candlestick-chart-candle"a candlealways; data-direction is up or down, data-dimmed while it slides out
data-slot="candlestick-chart-volume"a volume barthe volume band shows
data-slot="candlestick-chart-wick"a candle's wickalways
data-slot="candlestick-chart-body"a candle's bodyalways
data-slot="candlestick-chart-last-close"the last-close linethe data has a candle
data-slot="candlestick-chart-legend"the legendlegend is true
data-slot="chart-tooltip"the tooltipa period is inspected

Accessibility

  • The plot is a slider named after label ("ACME daily prices: inspect values"). Tab to it, then the arrow keys step through the periods, Home and End jump to the first and last, and Escape lets go. Its value text reads the tooltip: the period, its prices, its volume and its signed change.
  • Every value is also in a table hidden from sight, with the change for each period, so a screen reader can read the data without inspecting it.
  • Up and down are told apart by the sign of the change as well as by colour; legend names the two colours for readers who want a key.
  • Text never takes a candle's colour: prices and labels stay in the text colours.
  • loading sets aria-busy on the root and dims the last drawing until new data arrives.