CandlestickChart

Financial OHLC candlestick chart

Usage

CandlestickChart displays open, high, low and close (OHLC) values as candles. The candle body shows the open–close range, the thin line shows the high–low range:

Tick line
Grid axis
import { CandlestickChart } from '@mantine/charts';
import { data } from './data';

function Demo() {
  return <CandlestickChart h={300} data={data} dataKey="date"  />;
}

Data

Set dataKey to the property that is used for the x-axis. OHLC values are read from the open, high, low and close properties of each data item:

import { CandlestickChart } from '@mantine/charts';

const data = [
  { date: 'Mar 01', open: 136, high: 142, low: 133, close: 140 },
  { date: 'Mar 02', open: 140, high: 145, low: 138, close: 139 },
  { date: 'Mar 03', open: 139, high: 141, low: 129, close: 131 },
];

function Demo() {
  return <CandlestickChart h={300} data={data} dataKey="date" />;
}

The y-axis does not start at zero, its domain is calculated from the data. To change it, pass domain through yAxisProps.

Custom data keys

If your data uses keys other than open/high/low/close, map them with the dataKeys prop:

import { CandlestickChart } from '@mantine/charts';
import { data } from './data';

function Demo() {
  return (
    <CandlestickChart
      h={300}
      data={data}
      dataKey="day"
      dataKeys={{ open: 'o', high: 'h', low: 'l', close: 'c' }}
    />
  );
}

Colors

Use upColor and downColor props to change the colors of rising and falling candles. Both props accept theme colors and any valid CSS color:

import { CandlestickChart } from '@mantine/charts';
import { data } from './data';

function Demo() {
  return (
    <CandlestickChart
      h={300}
      data={data}
      dataKey="date"
      upColor="blue.7"
      downColor="orange.7"
    />
  );
}

Candle width

Use maxCandleWidth prop to limit the candle width in px:

import { CandlestickChart } from '@mantine/charts';
import { data } from './data';

function Demo() {
  return <CandlestickChart h={300} data={data} dataKey="date" maxCandleWidth={12} />;
}

Value formatter

Use valueFormatter prop to format values on the y-axis and inside the tooltip:

import { CandlestickChart } from '@mantine/charts';
import { data } from './data';

function Demo() {
  return (
    <CandlestickChart
      h={300}
      data={data}
      dataKey="date"
      valueFormatter={(value) => `$${value.toFixed(2)}`}
    />
  );
}

Tooltip labels

Use labels prop to change the open, high, low and close labels in the tooltip:

import { CandlestickChart } from '@mantine/charts';

function Demo() {
  return (
    <CandlestickChart
      data={data}
      dataKey="date"
      labels={{ open: 'Ouverture', high: 'Haut', low: 'Bas', close: 'Clôture' }}
    />
  );
}

Axis labels

Use xAxisLabel and yAxisLabel props to display axis labels:

import { CandlestickChart } from '@mantine/charts';
import { data } from './data';

function Demo() {
  return (
    <CandlestickChart
      h={300}
      data={data}
      dataKey="date"
      xAxisLabel="Date"
      yAxisLabel="Price"
    />
  );
}

Reference lines

Use referenceLines prop to highlight levels, for example, support and resistance:

import { CandlestickChart } from '@mantine/charts';
import { data } from './data';

function Demo() {
  return (
    <CandlestickChart
      h={300}
      data={data}
      dataKey="date"
      referenceLines={[
        { y: 160, label: 'Resistance', color: 'red.6' },
        { y: 128, label: 'Support', color: 'teal.6' },
      ]}
    />
  );
}