Skip to main content

CandlestickChart

Every example on this page is live, drawn by the library's Storybook, where you can also change its props and see the result.

An OHLC (Open, High, Low, Close) candlestick chart for financial data. Uses filled vs hollow bodies to distinguish up/down candles on monochrome displays.

The candles stretch to fill whatever box the chart is given, including a widget's stored preview, while wicks, outlines, patterns and labels keep their size. The date axis reaches past the first and last candles by enough for their bodies, so every body fits inside the chart, even with only two candles.

Import​

import { CandlestickChart } from "~lib/charts/candlestick-chart";

Props​

NameTypeRequiredDefaultDescription
dataCandlestickPoint[]YesN/AOHLC data points (min 2). See format below
axis{ y?: { name?, visible?, min?, max?, grid? }; x?: { ... } }NoN/AAxis configuration
widthnumber | stringNo300Chart width
heightnumber | stringNo300Chart height
upPattern"solid" | "diagonal" | "dots" | "crosshatch"Nonone (hollow)Fill pattern for up candles (close >= open)
downPattern"solid" | "diagonal" | "dots" | "crosshatch"No"solid"Fill pattern for down candles (close < open)

CandlestickPoint Format​

Each data point requires all five fields:

FieldTypeDescription
dateDate | numberTimestamp (Date object or ms)
opennumberOpening price
highnumberHighest price in the period
lownumberLowest price in the period
closenumberClosing price

Visual Encoding​

  • Wick (thin vertical line): spans from high to low
  • Body (rectangle): spans from open to close
  • Up candle (close >= open): hollow body (stroke only) by default
  • Down candle (close < open): solid-filled body by default
  • Doji (open === close): rendered as a thin horizontal line
  • Value axis: spans from the lowest low (or axis.y.min) to the highest high; axis.y.max adds headroom above the highest high but never cuts a wick short
  • Date axis: ticks fall on whole days, Mondays or months of the clock in axis.x.timeZone (or the zone axis.x.dateFormat names), and are written in it, so daily candles of a market in another zone line up with their ticks

Examples​

Simple​

Open Simple in Storybook

With Axes​

Open With Axes in Storybook

With Grid​

Open With Grid in Storybook

Bullish Trend​

Open Bullish in Storybook

Bearish Trend​

Open Bearish in Storybook

Two Candles​

Open Two Candles in Storybook

With Doji Candles​

Open With Doji in Storybook

Diagonal Down Pattern​

Open Diagonal Down Pattern in Storybook

Volatile Market​

Open Volatile in Storybook

Stock Data (20 Trading Days)​

Open Stock Data in Storybook

Intra-Day (Hourly)​

Open Intra Day in Storybook

See Also​