Candlestick Chart

OHLC candles with a volume strip. Unlike every other chart here it does not stretch — a stretched candle varies its body width with the container while the wick stays one unit, and the body-versus-wick reading stops working.

src/components/ui/candlestick-chart.tsx

About

From the component's own source, where it was written.

OHLC candles with an optional volume strip.

Candles are drawn in an unstretched SVG — a fixed viewBox scaled by the container, with preserveAspectRatio left at its default. Every other chart here stretches, but a stretched candle is a lie: the body width would vary with the container while the wick stays one unit, and the classic reading of body-versus-wick stops working.

The price axis is padded to the extremes of the *wicks*, not the bodies, or the highest high clips at the top edge exactly when it matters.

Install

npx astralyx-ui add candlestick-chart

Usage

import { CandlestickChart } from '@/components/ui/candlestick-chart'

<CandlestickChart candles={candles} />

Composer

Change the props and the source below follows.

8 candles, 62,518 to 67,782
UpDownVolume below
Props
tsx
<CandlestickChart candles={candles} showVolume={true} />

Examples

OHLC

API

Generated from the source, so it cannot fall behind the code. One table per exported component, then hooks, functions and types.

CandlestickChart

Extends Omit<ComponentProps<'figure'>, 'height'>.

PropTypeDefaultDescription
candlesCandle[]required{ time, open, high, low, close, volume? }.
heightnumber220—
showVolumebooleantrue—
upColorstring'var(--green)'—
downColorstring'var(--destructive)'—
localestring'en-GB'—
upLabelReactNode'Up'Legend entries.
downLabelReactNode'Down'—
volumeLabelReactNode'Volume below'—

Types

Candle

OHLC candles with an optional volume strip.

FieldTypeDescription
timestring | number—
opennumber—
highnumber—
lownumber—
closenumber—
volume?number—

Behaviour

TopicDetailDescription
axis paddingwicksThe scale is padded to the extremes of the wicks, not the bodies — otherwise the highest high clips exactly when it matters.
dojihandledA body with equal open and close still draws a visible line rather than a zero-height rect.