Open, high, low and close per period, with optional volume and a line at the latest close.
| Open | High | Low | Close | Volume | Change | |
|---|---|---|---|---|---|---|
| Nov 2 | $182.60 | $184.65 | $180.84 | $182.45 | 3.4M | – |
| Nov 3 | $182.50 | $184.00 | $179.04 | $181.12 | 4.8M | -0.73% |
| Nov 4 | $180.62 | $185.29 | $179.88 | $183.50 | 4.5M | +1.31% |
| Nov 5 | $183.50 | $186.49 | $183.49 | $185.02 | 4.8M | +0.83% |
| Nov 6 | $185.69 | $187.11 | $182.68 | $182.76 | 4.8M | -1.22% |
| Nov 9 | $181.88 | $183.76 | $178.62 | $179.89 | 3.7M | -1.57% |
| Nov 10 | $179.24 | $183.02 | $177.30 | $181.85 | 4.8M | +1.09% |
| Nov 11 | $181.75 | $181.87 | $177.38 | $178.72 | 5.8M | -1.72% |
| Nov 12 | $178.21 | $179.94 | $177.48 | $179.44 | 5.5M | +0.40% |
| Nov 13 | $180.16 | $180.92 | $179.48 | $180.43 | 3.8M | +0.55% |
| Nov 16 | $179.58 | $182.54 | $177.92 | $180.91 | 6.1M | +0.27% |
| Nov 17 | $180.09 | $184.44 | $177.83 | $183.41 | 4.5M | +1.38% |
| Nov 18 | $182.63 | $183.50 | $178.29 | $179.45 | 5.9M | -2.16% |
| Nov 19 | $180.25 | $181.98 | $175.26 | $177.50 | 4.7M | -1.09% |
| Nov 20 | $177.91 | $179.16 | $173.91 | $175.88 | 4M | -0.91% |
| Nov 23 | $176.87 | $179.72 | $175.83 | $177.52 | 4.8M | +0.93% |
| Nov 24 | $177.19 | $178.85 | $175.44 | $178.07 | 4M | +0.31% |
| Nov 25 | $177.97 | $182.25 | $175.58 | $180.58 | 6.5M | +1.41% |
| Nov 27 | $180.44 | $181.68 | $180.20 | $180.97 | 5.1M | +0.22% |
| Nov 30 | $180.60 | $184.98 | $180.38 | $182.81 | 5.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.
| Open | High | Low | Close | Volume | Change | |
|---|---|---|---|---|---|---|
| 09:30 | 182.40 | 182.99 | 182.04 | 182.87 | 302K | – |
| 09:31 | 182.87 | 183.12 | 182.16 | 182.57 | 93K | -0.16% |
| 09:32 | 182.57 | 183.34 | 182.17 | 182.80 | 241K | +0.13% |
| 09:33 | 182.80 | 183.49 | 182.45 | 183.11 | 289K | +0.17% |
| 09:34 | 183.11 | 183.81 | 182.53 | 183.60 | 125K | +0.27% |
| 09:35 | 183.60 | 184.09 | 182.88 | 182.89 | 152K | -0.39% |
| 09:36 | 182.89 | 184.10 | 182.72 | 183.59 | 190K | +0.38% |
| 09:37 | 183.59 | 184.53 | 183.24 | 184.18 | 185K | +0.32% |
| 09:38 | 184.18 | 184.85 | 183.90 | 184.55 | 300K | +0.20% |
| 09:39 | 184.55 | 184.81 | 183.58 | 183.81 | 139K | -0.40% |
| 09:40 | 183.81 | 184.39 | 183.65 | 184.35 | 131K | +0.29% |
| 09:41 | 184.35 | 184.69 | 183.46 | 183.84 | 206K | -0.28% |
| 09:42 | 183.84 | 184.15 | 183.60 | 183.82 | 224K | -0.01% |
| 09:43 | 183.82 | 184.90 | 183.50 | 184.55 | 145K | +0.40% |
| 09:44 | 184.55 | 185.14 | 183.81 | 184.02 | 88K | -0.29% |
| 09:45 | 184.02 | 184.14 | 183.54 | 183.85 | 267K | -0.09% |
| 09:46 | 183.85 | 184.70 | 183.80 | 184.63 | 318K | +0.42% |
| 09:47 | 184.63 | 185.10 | 184.01 | 184.58 | 120K | -0.03% |
| 09:48 | 184.58 | 185.62 | 184.18 | 185.40 | 174K | +0.44% |
| 09:49 | 185.40 | 185.83 | 185.01 | 185.46 | 86K | +0.03% |
| 09:50 | 185.46 | 186.16 | 184.97 | 186.00 | 156K | +0.29% |
| 09:51 | 186.00 | 186.79 | 185.54 | 186.43 | 307K | +0.23% |
| 09:52 | 186.43 | 186.93 | 185.79 | 186.30 | 189K | -0.07% |
| 09:53 | 186.30 | 186.78 | 185.33 | 185.78 | 118K | -0.28% |
| 09:54 | 185.78 | 186.37 | 185.35 | 185.40 | 103K | -0.20% |
| 09:55 | 185.40 | 186.68 | 185.07 | 186.23 | 138K | +0.45% |
| 09:56 | 186.23 | 186.59 | 185.32 | 185.52 | 174K | -0.38% |
| 09:57 | 185.52 | 185.97 | 185.01 | 185.14 | 82K | -0.20% |
| 09:58 | 185.14 | 186.00 | 184.69 | 185.82 | 106K | +0.37% |
| 09:59 | 185.82 | 186.66 | 185.50 | 186.52 | 223K | +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
| Open | High | Low | Close | Change | |
|---|---|---|---|---|---|
| Sep 7 | 171.20 | 176.40 | 169.80 | 175.10 | – |
| Sep 14 | 175.10 | 178.90 | 172.30 | 173.00 | -1.20% |
| Sep 21 | 173.00 | 174.20 | 166.50 | 167.90 | -2.95% |
| Sep 28 | 167.90 | 172.80 | 165.10 | 171.60 | +2.20% |
| Oct 5 | 171.60 | 179.50 | 170.90 | 178.80 | +4.20% |
| Oct 12 | 178.80 | 183.20 | 176.40 | 181.70 | +1.62% |
| Oct 19 | 181.70 | 182.60 | 175.30 | 176.20 | -3.03% |
| Oct 26 | 176.20 | 181.00 | 174.80 | 180.30 | +2.33% |
| Nov 2 | 180.30 | 187.10 | 179.00 | 182.80 | +1.39% |
| Nov 9 | 182.80 | 183.80 | 177.30 | 180.40 | -1.31% |
| Nov 16 | 180.40 | 184.40 | 173.90 | 175.90 | -2.49% |
| Nov 23 | 175.90 | 185.00 | 175.40 | 182.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
revealrole, once per mount. - Slide: when
datachanges, candles that stay move to their new place and size on themoverole. 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
gliderole.
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>.
| Prop | Type | Default |
|---|---|---|
data | TDatum[] | required |
index | keyof TDatum | required |
label | string | required: the accessible name |
config | CandlestickConfig | Up in success, Down in destructive |
volume | boolean | on when the data has volume |
formatValue | (value: number, key: string) => string | 1,234.50, volume 4.8M |
formatIndex | (value: string, datum: TDatum) => string | the field as text |
legend | boolean | false |
tooltip | boolean | true |
animate | boolean | true |
loading | boolean | false |
empty | ReactNode | "No data" |
onActiveChange | (active: ChartActive<TDatum> | null) => void | - |
CandlestickConfig#
| Field | Type | Default |
|---|---|---|
up | { label?: string; color?: ChartColor } | { label: "Up", color: "success" } |
down | { label?: string; color?: ChartColor } | { label: "Down", color: "destructive" } |
Data attributes#
| Attribute | Element | Present when |
|---|---|---|
data-slot="candlestick-chart" | root | always |
data-loading | root | loading is true |
data-slot="chart-plot" | the plot | always |
data-slot="candlestick-chart-candle" | a candle | always; data-direction is up or down, data-dimmed while it slides out |
data-slot="candlestick-chart-volume" | a volume bar | the volume band shows |
data-slot="candlestick-chart-wick" | a candle's wick | always |
data-slot="candlestick-chart-body" | a candle's body | always |
data-slot="candlestick-chart-last-close" | the last-close line | the data has a candle |
data-slot="candlestick-chart-legend" | the legend | legend is true |
data-slot="chart-tooltip" | the tooltip | a 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;
legendnames the two colours for readers who want a key. - Text never takes a candle's colour: prices and labels stay in the text colours.
loadingsetsaria-busyon the root and dims the last drawing until new data arrives.