CandlestickChart

Financial OHLC candlestick chart for visualizing stock prices, crypto markets, and other time-series price data. Supports volume bars, interactive tooltips, zoom and pan, and crosshair cursor.

Playground

Hover over candles to see OHLC values. Green candles indicate price increase (close > open), red candles indicate price decrease. Use mouse wheel to zoom and drag to pan. A crosshair follows your cursor for precise value reading.

Props

Midnight
OffOn
OffOn
OffOn
Code
<CandlestickChart
  data={data}
  theme="midnight"
  showVolume
  enableZoom
  showZoomControls
/>

Basic Usage

Import the component and provide OHLC data:

tsx
import { CandlestickChart } from '@derpdaderp/chartkit';

const data = [
  { time: 'Jan 1', open: 150.00, high: 155.50, low: 148.20, close: 153.80, volume: 2500000 },
  { time: 'Jan 2', open: 153.80, high: 158.00, low: 152.10, close: 149.50, volume: 3100000 },
  { time: 'Jan 3', open: 149.50, high: 152.30, low: 147.80, close: 151.20, volume: 2800000 },
  // ...more data
];

<CandlestickChart
  data={data}
  theme="midnight"
  height={400}
/>

With Volume Bars

Enable volume visualization with the showVolume prop:

140.99165.56190.13214.70239.27May 6Jul 5Sep 3Nov 2Jan 1Mar 1
tsx
<CandlestickChart
  data={data}
  theme="midnight"
  showVolume
  volumeHeight={0.2}  // 20% of chart height for volume
/>

Custom Colors

Override the default bullish/bearish colors:

140.99165.56190.13214.70239.27May 6Jul 5Sep 3Nov 2Jan 1Mar 1
tsx
<CandlestickChart
  data={data}
  theme="midnight"
  upColor="#00d4aa"
  downColor="#ff6b6b"
/>

Price Formatting

Format Y-axis values with a custom formatter:

tsx
// Format as currency
<CandlestickChart
  data={data}
  theme="midnight"
  formatY={(value) => `$${value.toFixed(2)}`}
/>

// Format for crypto (more decimals)
<CandlestickChart
  data={cryptoData}
  theme="midnight"
  formatY={(value) => value.toFixed(6)}
/>

Zoom and Pan

CandlestickChart supports interactive zoom and pan out of the box, making it easy to explore large datasets. This is enabled by default.

Interactions

  • Mouse wheel - Scroll to zoom in/out (zooms toward cursor position)
  • Click and drag - Pan left/right through the data
  • Zoom controls - Use the +/- buttons in the top-right corner
  • Reset button - Click "Reset" to show all data
  • Crosshair - A crosshair follows your cursor for precise value reading
tsx
// Zoom and pan enabled by default
<CandlestickChart
  data={data}
  theme="midnight"
  enableZoom        // default: true
  showZoomControls  // default: true
  minVisibleCandles={10}
/>

// Disable zoom for static charts
<CandlestickChart
  data={data}
  theme="midnight"
  enableZoom={false}
/>

// Control visible range programmatically
<CandlestickChart
  data={data}
  theme="midnight"
  initialRange={[0, 30]}  // Show first 30 candles
  onRangeChange={(range) => console.log('Visible:', range)}
/>

Responsive

Use the responsive prop to auto-fill container width:

tsx
<CandlestickChart
  data={data}
  theme="midnight"
  responsive
  height={400}
  showVolume
/>

Props

PropTypeDefaultDescription
data*CandlestickDataPoint[]-OHLC data array
theme*ThemeName-Theme name
widthnumber600Chart width (ignored if responsive)
heightnumber400Chart height in pixels
responsivebooleanfalseAuto-fill container width
showVolumebooleanfalseShow volume bars at bottom
volumeHeightnumber0.2Volume section height ratio (0-1)
upColorstring-Bullish candle color (default: theme positive)
downColorstring-Bearish candle color (default: theme negative)
wickWidthnumber1Wick line width in pixels
candleWidthnumber0.7Candle body width ratio (0-1)
gridGridOptions | booleantrueGrid line configuration
formatY(value: number) => string-Y-axis value formatter
renderTooltipfunction-Custom tooltip renderer
enableZoombooleantrueEnable zoom and pan interactions
showZoomControlsbooleantrueShow +/- zoom control buttons
minVisibleCandlesnumber10Minimum candles visible when zoomed in
initialRange[number, number]-Initial visible range [startIndex, endIndex]
onRangeChange(range: [number, number]) => void-Callback when visible range changes

CandlestickDataPoint

Each data point requires OHLC values:

PropTypeDefaultDescription
time*string-Time/date label for X-axis
open*number-Opening price
high*number-Highest price
low*number-Lowest price
close*number-Closing price
volumenumber-Trading volume (optional)

Reading Candlestick Charts

  • Green candles - Bullish (close > open), price went up
  • Red candles - Bearish (close < open), price went down
  • Wick (thin line) - Shows the high and low prices
  • Body (thick rectangle) - Shows the open and close prices
  • Volume bars - Trading activity, higher = more trades
  • Crosshair - Guides your eye to exact values on hover