Aller au contenu principal

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​

Ouvrir Simple dans Storybook

With Axes​

Ouvrir With Axes dans Storybook

With Grid​

Ouvrir With Grid dans Storybook

Bullish Trend​

Ouvrir Bullish dans Storybook

Bearish Trend​

Ouvrir Bearish dans Storybook

Two Candles​

Ouvrir Two Candles dans Storybook

With Doji Candles​

Ouvrir With Doji dans Storybook

Diagonal Down Pattern​

Ouvrir Diagonal Down Pattern dans Storybook

Volatile Market​

Ouvrir Volatile dans Storybook

Stock Data (20 Trading Days)​

Ouvrir Stock Data dans Storybook

Intra-Day (Hourly)​

Ouvrir Intra Day dans Storybook

See Also​