---
title: "Candlestick Chart"
description: "Live OHLC candles with volume, a last-price line, and a crosshair readout."
category: "Charts"
publishedAt: "2026-10-12"
updatedAt: "2026-11-25"
documentation: "https://beui.dev/charts/candlestick-chart"
markdown: "https://beui.dev/charts/candlestick-chart.md"
license: "MIT"
---

# Candlestick Chart

> Live OHLC candles with volume, a last-price line, and a crosshair readout.

## Install

```bash
npx shadcn@latest add @beui/candlestick-chart
```

## Dependencies

- `clsx`
- `lucide-react`
- `motion`
- `react`
- `tailwind-merge`

## Usage

```tsx
"use client";

import {
  type Candle,
  CandlestickChart,
  CandlestickChartLegend,
  CandlestickChartPlot,
} from "@/components/charts/candlestick-chart";

/** Pass candles oldest first with stable ids. Update the last candle as trades
 * print and append a new one when its interval opens. */
export function CandlestickChartExample({
  candles,
  lastPrice,
}: {
  candles: readonly Candle[];
  lastPrice?: number;
}) {
  return (
    <CandlestickChart
      candles={candles}
      lastPrice={lastPrice}
      label="ETH / USD, 5 minute candles"
      formatPrice={(value) => value.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 })}
    >
      <CandlestickChartLegend />
      <CandlestickChartPlot height={320} className="mt-4" />
    </CandlestickChart>
  );
}
```

## API Reference

### CandlestickChart

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `candles` | `readonly Candle[]` | — | Yes | Price candles in time order, each with open, high, low, close and volume. |
| `lastPrice` | `number` | — | No | Draws a dashed line and tag at this price, usually the last trade. |
| `activeId` | `string \| null` | — | No | Controlled crosshair candle, by `id`, so it stays on the same candle as new ones arrive. Pair with `onActiveIdChange`. |
| `defaultActiveId` | `string \| null` | — | No | The initial crosshair candle id when uncontrolled. Default: null |
| `onActiveIdChange` | `((id: string \| null) => void)` | — | No | Called with the candle id, or `null`, when the crosshair moves or leaves. |
| `formatPrice` | `((value: number) => string)` | — | No | Formats prices on the axis, readout and last-price tag. Defaults to up to 2 decimals. |
| `formatVolume` | `((value: number) => string)` | — | No | Formats volume in the readout. Defaults to compact notation (1.2K). |
| `label` | `string` | — | No | Accessible name for the chart. |
| `labels` | `Partial<{ label: string; candle: string; open: string; high: string; low: string; close: string; volume: string; valueText: string; }>` | — | No | Override any built-in string. |
| `className` | `string` | — | No | Classes merged onto the root element. |

### CandlestickChartLegend

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `children` | `((candle: Candle, change: number) => ReactNode)` | — | No | Custom readout. Receives the crosshair candle, or the latest one. |
| `className` | `string` | — | No | Classes merged onto the root element. |

### CandlestickChartPlot

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `height` | `number` | `320` | No | Plot height in px. |
| `className` | `string` | — | No | Classes merged onto the root element. |

## Types

### Candle

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | Yes | Stable id, such as the open timestamp. |
| `label` | `string` | Yes | Axis and readout label, such as "14:05". |
| `open` | `number` | Yes | Price at the start of the period. Green when `close` is at or above it. |
| `high` | `number` | Yes | Highest price in the period, the top of the wick. |
| `low` | `number` | Yes | Lowest price in the period, the bottom of the wick. |
| `close` | `number` | Yes | Price at the end of the period. |
| `volume` | `number` | Yes | Amount traded in the period, drawn as a bar along the bottom. |

## About Candlestick Chart

Candlestick Chart is an animated React OHLC chart for price data. It draws open, high, low and close candles with volume bars underneath, a dashed last-price line with a price tag, and a crosshair with an axis price tag and an OHLC readout. When new trades arrive, the live candle's body, wick and volume spring to their new values with Framer Motion using transforms only, so the chart handles streaming data smoothly.

### When to use it

- A crypto or stock trading app shows live price action for a market.
- A portfolio or asset page shows recent price history with volume.
- A trading dashboard needs a crosshair readout of open, high, low and close for any candle.

### Accessibility

The plot is a focusable element with the slider role, and its value text reads the active candle's label with its open, high, low and close prices. Arrow Left and Arrow Right move the crosshair one candle, Home and End jump to the first and last candle, and Escape clears it. With reduced motion enabled, candles skip their fade in and values update in place without springs.

### FAQ

**How do I make a candlestick chart in React?**

Install the chart with the shadcn CLI and pass candles to CandlestickChart, each with an id, label, open, high, low, close and volume. Compose CandlestickChartLegend and CandlestickChartPlot inside it, or leave children empty for the default layout.

**Does it work with live price data?**

Yes. Update the candles array as trades print and set lastPrice to the latest trade. Candles keep their identity by id, so the crosshair stays on the same candle as new ones arrive.

**Can I format prices and volume?**

Yes. Pass formatPrice and formatVolume to CandlestickChart. Use activeId with onActiveIdChange to control the crosshair, and the height prop on CandlestickChartPlot to size the plot.

## Source

- Registry detail: https://beui.dev/r/candlestick-chart
- Raw source: https://beui.dev/r/candlestick-chart/raw
- GitHub: https://github.com/starc007/ui-components
