Skip to content
WANCRAFT

G.209Data & Feedback

Candlestick Chart

An OHLC candlestick chart with volume, a moving average, crosshair tooltip, wheel / drag pan-zoom and candle-by-candle keys.

NewReactSVGTailwindadvanced

Overview

Candlestick Chart draws open, high, low and close as SVG candles: up candles are hollow and down candles filled, so direction reads without colour, with volume bars in a pane below and a simple moving average of any period on top. Hover for a crosshair that snaps to the candle, tags the price under the pointer and shows an OHLC tooltip with the change and volume. The wheel zooms around the pointer, horizontal scroll or a drag pans, and the price axis rescales to what is visible. Focus the chart and the arrow keys walk candle by candle, announcing each one ("3 Oct: open 41.20, high 43.00, low 40.80, close 42.60"); Page Up / Page Down jump a screen and + / − zoom. A screen-reader summary gives the period, range and change, the chart resizes with its container through ResizeObserver, and randomWalkCandles() provides seeded, deterministic sample data.

01Installation

Method 01 · Registry

CLI verified

Uses the shadcn CLI in a project initialised with shadcn init. Installs the file to components/ui/candlestick-chart.tsx and adds its dependencies.

npx shadcn@latest add https://wancraft.my/r/candlestick-chart.json

Method 02 · Copy and paste

  1. 1. No extra dependencies — React and Tailwind CSS only.
  2. 2. Copy the source from the Code tab into components/ui/candlestick-chart.tsx.
  3. 3. Import it and adjust props.
Dependencies
None
Peer
react ≥ 18, tailwindcss ≥ 4
Added
13 Oct 2026
Updated
—

02Usage

The default configuration. Change properties above to generate a tailored example in the Usage tab.

example.tsx
import { CandlestickChart, randomWalkCandles } from "@/components/ui/candlestick-chart";

export function CandlestickChartExample() {
  const candles = randomWalkCandles({ count: 160, seed: 10 });

  return (
    <div className="w-full max-w-4xl">
      <CandlestickChart data={candles} label="Daily price, sample series" />
    </div>
  );
}

03Props

PropTypeDefaultDescription
dataCandle[]—Required. { t, open, high, low, close, volume? } — t is "YYYY-MM-DD", ISO or epoch ms.
labelstring—Required accessible name of the chart.
heightnumber360Total height in px, including the volume pane and date axis.
showVolumebooleantrueVolume bars in a pane under the price.
maPeriodnumber20Simple moving average of closes; 0 or 1 hides it.
hollowUpbooleantrueHollow up candles and filled down candles (the non-colour cue).
initialCountnumber60Candles visible at first, anchored to the latest.
minCountnumber12Fewest candles you can zoom in to.
upColor / downColorstring"#3FB984" / "#F2555A"Candle, wick and volume colours.
accentstring"#FF7448"Moving average, crosshair price tag and focus ring.
precisionnumber2Decimals for prices on the axis, tooltip and announcements.
localestring"en-GB"Dates and compact volumes via Intl.
randomWalkCandles(options)({ count?, seed?, start?, price?, volatility? }) => Candle[]—Exported helper: seeded weekday random walk for demos — identical on server and client.

04Features

  • 01SVG candles with wicks; up hollow and down filled so direction does not rely on colour
  • 02Volume pane and a configurable simple moving average computed over the whole series
  • 03Crosshair snapping to candles with a price tag and an OHLC + change + volume tooltip
  • 04Wheel zooms around the pointer, horizontal wheel / drag pans; the price axis fits the visible range
  • 05Keyboard: arrows read candle by candle with announcements, Page Up / Down, Home / End, + / − zoom
  • 06ResizeObserver sizing; pointer updates are imperative and pan / zoom commits once per frame
input · pointerinput · draginput · keyboardinput · hover

05Accessibility

  • The plot is a focusable group (aria-roledescription "candlestick chart") named by label and described by a summary of the period, first open, last close, change and range, plus the key help.
  • Left / Right move one candle, Page Up / Page Down a screen, Home / End to the ends, + / − zoom; each candle is announced politely as "3 Oct: open 41.20, high 43.00, low 40.80, close 42.60", and the view pans to keep it visible.
  • Escape hides the keyboard crosshair without leaving the chart; the focus ring is the accent colour.
  • Up and down are distinguished by shape (hollow vs filled) and by ▲ / ▼ in the tooltip, not by colour alone.
  • The SVG, legend and tooltip are aria-hidden duplicates of the summary and announcements. There are no animations to reduce.

06Limitations

  • Linear price scale and a single series; no indicators beyond the simple moving average.
  • Every visible candle is an SVG element — fine for hundreds, but use canvas for tens of thousands.
  • On touch, horizontal drags pan; pinch-to-zoom is not handled (use the keyboard or a wheel).