Candlestick Chart

A customizable candlestick chart component with animations for financial data visualization.

Installation

pnpm dlx bna-ui add candlestick-chart

Usage

import { CandlestickChart } from '@/components/charts/candlestick-chart';
const data = [
  { date: 'Jan 1', open: 100, high: 120, low: 95, close: 110 },
  { date: 'Jan 2', open: 110, high: 125, low: 105, close: 115 },
  { date: 'Jan 3', open: 115, high: 130, low: 110, close: 125 },
  { date: 'Jan 4', open: 125, high: 140, low: 120, close: 135 },
];
 
<CandlestickChart
  data={data}
  config={{
    height: 200,
    showGrid: true,
    showLabels: true,
    animated: true,
  }}
/>;

Examples

Basic Candlestick Chart

Interactive Candlestick Chart

Styled Candlestick Chart

Minimal Candlestick Chart

API Reference

CandlestickChart

A customizable candlestick chart component for financial data visualization with smooth animations.

PropTypeDefaultDescription
dataCandlestickDataPoint[]-Array of candlestick data points to display.
configChartConfig{}Configuration object for chart appearance.
styleViewStyle-Additional styles to apply to the chart.

CandlestickDataPoint

PropertyTypeDefaultDescription
datestring-The date/time label for the candle.
opennumber-The opening price for the period.
highnumber-The highest price for the period.
lownumber-The lowest price for the period.
closenumber-The closing price for the period.

ChartConfig

PropertyTypeDefaultDescription
widthnumber-Fixed width of the chart (auto-sizes if omitted).
heightnumber200Height of the chart.
paddingnumber20Padding around the chart.
showGridbooleantrueWhether to show grid lines.
showLabelsbooleantrueWhether to show date labels.
animatedbooleantrueWhether to animate the chart on load.
durationnumber800Animation duration in milliseconds.

Features

  • Smooth Animations: Built-in animations using React Native Reanimated
  • Financial Data: Specialized for OHLC (Open, High, Low, Close) data
  • Color Coding: Automatic bullish (green) and bearish (red) candle colors
  • Responsive Design: Automatically adapts to container width
  • Customizable Grid: Optional grid lines for better readability
  • Smart Spacing: Automatic candle width and spacing calculations
  • Theme Integration: Uses theme colors for consistent styling
  • Interactive Touch: Optional touch gestures for data exploration

Accessibility

The CandlestickChart component is built with accessibility in mind:

  • Semantic SVG structure for screen readers
  • Proper contrast ratios for visual elements
  • Touch targets meet minimum size requirements
  • Supports dynamic text sizing
  • Keyboard navigation support (when interactive)

Performance

The component is optimized for performance:

  • Uses React Native Reanimated for smooth 60fps animations
  • Efficient SVG rendering with minimal re-renders
  • Gesture handling optimized for touch interactions
  • Automatic cleanup of animation values

Financial Data Visualization

The candlestick chart is specifically designed for financial data:

  • Bullish Candles: Green candles when close > open (price increased)
  • Bearish Candles: Red candles when close < open (price decreased)
  • Wicks: Show the full price range (high and low) for each period
  • Body: Shows the open and close prices for each period
  • Automatic Scaling: Prices are automatically scaled to fit the chart area