# Candlestick Chart

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

Source: https://www.honestui.com/docs/charts/candlestick-chart/static

### Daily share price

```tsx
"use client";

import { CandlestickChart, type ChartConfig } from "honestui/charts";

// Scenario: A share price over 40 trading days
const data = (() => {
  const rows: { date: string; open: number; close: number; high: number; low: number; volume?: number }[] = [];
  let close = 182.4;
  const day = new Date(Date.UTC(2026, 8, 1));
  while (rows.length < 40) {
    const weekday = day.getUTCDay();
    if (weekday !== 0 && weekday !== 6) {
      const i = rows.length;
      const open = Math.round((close + Math.sin(i * 2.3) * 0.9) * 100) / 100;
      close = Math.round((open + Math.sin(i * 0.55) * 2.6 + Math.cos(i * 1.7) * 1.4 + 0.18) * 100) / 100;
      rows.push({
        date: day.toISOString().slice(0, 10),
        open,
        close,
        high: Math.round((Math.max(open, close) + 0.6 + Math.abs(Math.sin(i * 3.1)) * 1.8) * 100) / 100,
        low: Math.round((Math.min(open, close) - 0.6 - Math.abs(Math.cos(i * 2.7)) * 1.8) * 100) / 100,
      });
    }
    day.setUTCDate(day.getUTCDate() + 1);
  }
  return rows;
})();

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

const shortDate = (value: string) =>
  new Date(`${value}T00:00:00Z`).toLocaleDateString("en-US", {
    month: "short",
    day: "numeric",
    timeZone: "UTC",
  });

export function ExampleCandlestickChart() {
  return (
    <CandlestickChart data={data} config={chartConfig} xDataKey="date" className="h-full w-full p-4">
      <CandlestickChart.Grid />
      <CandlestickChart.XAxis tickFormatter={shortDate} />
      <CandlestickChart.YAxis tickFormatter={(value) => `$${value.toFixed(0)}`} />
      <CandlestickChart.Tooltip valueFormatter={(value) => `$${value.toFixed(2)}`} />
      <CandlestickChart.Candles />
    </CandlestickChart>
  );
}

```

## Overview [#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](/docs/charts/line-chart/static) is easier to read.

## Anatomy [#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 [#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 [#installation]

<CommandBlock commands="[&#x22;honestui&#x22;]" />

## Usage [#usage]

```tsx
import { CandlestickChart, type ChartConfig } from "honestui/charts";
```

```tsx
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 [#examples]

### Volume and Brush [#volume-and-brush]

### Volume and Brush

```tsx
"use client";

import { CandlestickChart, type ChartConfig } from "honestui/charts";

// Scenario: Six months of daily prices and trading volume, zoomable with the brush
const data = (() => {
  const rows: { date: string; open: number; close: number; high: number; low: number; volume?: number }[] = [];
  let close = 64.2;
  const day = new Date(Date.UTC(2026, 3, 1));
  while (rows.length < 126) {
    const weekday = day.getUTCDay();
    if (weekday !== 0 && weekday !== 6) {
      const i = rows.length;
      const open = Math.round((close + Math.sin(i * 1.9) * 0.4) * 100) / 100;
      const drift = Math.sin(i * 0.08) * 0.35 + Math.sin(i * 0.61) * 0.9 + Math.cos(i * 1.37) * 0.6;
      close = Math.round((open + drift) * 100) / 100;
      const move = Math.abs(close - open);
      rows.push({
        date: day.toISOString().slice(0, 10),
        open,
        close,
        high: Math.round((Math.max(open, close) + 0.2 + Math.abs(Math.sin(i * 2.9)) * 0.8) * 100) / 100,
        low: Math.round((Math.min(open, close) - 0.2 - Math.abs(Math.cos(i * 2.3)) * 0.8) * 100) / 100,
        volume: Math.round(1_800_000 + move * 1_400_000 + Math.abs(Math.sin(i * 0.7)) * 900_000),
      });
    }
    day.setUTCDate(day.getUTCDate() + 1);
  }
  return rows;
})();

const chartConfig = {
  up: { label: "Up", colors: { light: ["#0d9488"], dark: ["#2dd4bf"] } },
  down: { label: "Down", colors: { light: ["#e11d48"], dark: ["#fb7185"] } },
} satisfies ChartConfig;

const shortDate = (value: string) =>
  new Date(`${value}T00:00:00Z`).toLocaleDateString("en-US", {
    month: "short",
    day: "numeric",
    timeZone: "UTC",
  });

export function ExampleVolumeCandlestickChart() {
  return (
    <CandlestickChart
      data={data}
      config={chartConfig}
      xDataKey="date"
      volumeDataKey="volume"
      className="h-full w-full p-4"
    >
      <CandlestickChart.Grid />
      <CandlestickChart.XAxis tickFormatter={shortDate} />
      <CandlestickChart.YAxis tickFormatter={(value) => `$${value.toFixed(0)}`} />
      <CandlestickChart.Brush formatLabel={shortDate} />
      <CandlestickChart.Tooltip valueFormatter={(value) => `$${value.toFixed(2)}`} />
      <CandlestickChart.Volume height={0.22} />
      <CandlestickChart.Candles variant="hollow" />
    </CandlestickChart>
  );
}

```

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 [#zoom-and-reference-line]

<ComponentPreview title="<CandlestickChart.Zoom />" name="ex-zoom-echarts-candlestick-chart" />

`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](/docs/charts/ui/brush) and [Reference Lines](/docs/charts/ui/reference-lines).

Give the chart a `syncId` to move its crosshair with other charts over the same dates, such as a [combo chart](/docs/charts/combo-chart/static) of trading activity below it.

### Loading State [#loading-state]

### isLoading='true'

```tsx
"use client";

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;

export function ExampleLoadingCandlestickChart() {
  return (
    <CandlestickChart
      data={[]}
      config={chartConfig}
      xDataKey="date"
      isLoading
      className="h-full w-full p-4"
    >
      <CandlestickChart.Grid />
      <CandlestickChart.Volume />
      <CandlestickChart.Candles />
    </CandlestickChart>
  );
}

```

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

## API Reference [#api-reference]

<ApiHeading>
  CandlestickChart
</ApiHeading>


  ### `data`

type: `TData[]`

One row per period, oldest first.

  ### `config`

type: `ChartConfig`

Labels and colors for `up` and `down`.

  ### `xDataKey`

type: `keyof TData & string`

The period field.

  ### `openDataKey`

type: `keyof TData & string` · default: `&#x22;open&#x22;`

Opening price field.

  ### `highDataKey`

type: `keyof TData & string` · default: `&#x22;high&#x22;`

High price field.

  ### `lowDataKey`

type: `keyof TData & string` · default: `&#x22;low&#x22;`

Low price field.

  ### `closeDataKey`

type: `keyof TData & string` · default: `&#x22;close&#x22;`

Closing price field.

  ### `volumeDataKey`

type: `keyof TData & string`

Volume field, drawn when `Volume` is present.

  ### `animation`

type: `boolean` · default: `true`

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

  ### `isLoading`

type: `boolean` · default: `false`

Shows neutral candles and the loading label.

  ### `syncId`

type: `string`

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

  ### `ariaLabel`

type: `string`

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

  ### `chartOptions`



">
    Escape hatch merged over the generated ECharts option.


<ApiHeading>
  Candles
</ApiHeading>


  ### `variant`

type: `&#x22;filled&#x22; | &#x22;hollow&#x22;` · default: `&#x22;filled&#x22;`

`hollow` leaves rising bodies open.

  ### `width`

type: `number` · default: `0.6`

Body width as a share of each period.

  ### `maxWidth`

type: `number` · default: `14`

Widest a body may grow, in pixels.


<ApiHeading>
  Volume
</ApiHeading>


  ### `height`

type: `number` · default: `0.2`

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


<ApiHeading>
  YAxis
</ApiHeading>


  ### `position`

type: `&#x22;left&#x22; | &#x22;right&#x22;` · default: `&#x22;right&#x22;`

Side of the price scale.

  ### `tickFormatter`



string">
    Formats price labels.

  ### `label`

type: `string`

Axis title.

  ### `hideDots`

type: `boolean` · default: `false`

Hides the tick dots.


<ApiHeading>
  XAxis
</ApiHeading>


  ### `tickFormatter`



string">
    Formats period labels and the crosshair's period label.

  ### `label`

type: `string`

Axis title.

  ### `hideDots`

type: `boolean` · default: `false`

Hides the tick dots.


<ApiHeading>
  Tooltip
</ApiHeading>


  ### `crosshair`

type: `boolean` · default: `true`

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

  ### `valueFormatter`



string">
    Formats prices in the tooltip and the crosshair label.

  ### `volumeFormatter`



string">
    Formats volume. Defaults to compact notation.

  ### `labelFormatter`



string">
    Formats the period shown as the tooltip title. Defaults to the XAxis `tickFormatter`.

  ### `variant`

type: `&#x22;default&#x22; | &#x22;frosted-glass&#x22;` · default: `&#x22;default&#x22;`

Tooltip surface.

  ### `roundness`

type: `&#x22;sm&#x22; | &#x22;md&#x22; | &#x22;lg&#x22; | &#x22;xl&#x22;` · default: `&#x22;lg&#x22;`

Tooltip corner radius.

  ### `position`

type: `&#x22;fixed&#x22; | &#x22;variable&#x22;` · default: `&#x22;variable&#x22;`

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

  ### `defaultIndex`

type: `number`

Opens the tooltip at a period after mount.


<ApiHeading>
  Brush
</ApiHeading>


  ### `height`

type: `number` · default: `56`

Height of the preview strip in pixels.

  ### `formatLabel`



string">
    Formats the range labels shown while the brush is hovered.

  ### `onChange`



void">
    Fires when the selected range changes.


<ApiHeading>
  Zoom, ReferenceLine, ReferenceArea, ReferenceDot
</ApiHeading>

`CandlestickChart.Zoom` takes the props listed in [Brush and Zoom](/docs/charts/ui/brush). The reference parts take the props listed in [Reference Lines](/docs/charts/ui/reference-lines); a `y` value is a price.
