Skip to content

Candlestick and OHLC

Financial series: openField / highField / lowField / closeField. The X axis is ordinal-time: each point occupies a band, so weekends leave no gaps.

ts
import { getData } from './data';
import type { ChartOptions } from 'grafit-charts';

export function createOptions(): ChartOptions {
  return {
    data: getData(),
    title: { text: 'CHRT / USD' },
    series: [{ type: 'candlestick', xField: 'date', openField: 'open', highField: 'high', lowField: 'low', closeField: 'close' }],
    axes: [
      { type: 'ordinal-time', position: 'bottom' },
      { type: 'number', position: 'right' },
    ],
    zoom: { enabled: true },
    crosshair: { enabled: true },
    legend: { enabled: false },
  };
}
ts
export function getData() {
  const start = Date.UTC(2025, 8, 1);
  const day = 24 * 60 * 60 * 1000;
  const data: Array<{ date: Date; open: number; high: number; low: number; close: number }> = [];
  let price = 250;
  for (let i = 0; i < 45; i++) {
    const weekday = new Date(start + i * day).getUTCDay();
    if (weekday === 0 || weekday === 6) continue; // ordinal-time leaves no gaps
    const drift = Math.sin(i / 6) * 3 + ((i * 11) % 7) - 3;
    const open = price;
    const close = Math.round((price + drift) * 100) / 100;
    const high = Math.max(open, close) + ((i * 5) % 4) + 1;
    const low = Math.min(open, close) - ((i * 3) % 4) - 1;
    data.push({ date: new Date(start + i * day), open, high, low, close });
    price = close;
  }
  return data;
}

OHLC bars

ts
import { getData } from './data';
import type { ChartOptions } from 'grafit-charts';

export function createOptions(): ChartOptions {
  return {
    data: getData(),
    title: { text: 'OHLC bars' },
    series: [{ type: 'ohlc', xField: 'date', openField: 'open', highField: 'high', lowField: 'low', closeField: 'close' }],
    axes: [
      { type: 'ordinal-time', position: 'bottom' },
      { type: 'number', position: 'right' },
    ],
    legend: { enabled: false },
  };
}
ts
export function getData() {
  const start = Date.UTC(2025, 10, 3);
  const day = 24 * 60 * 60 * 1000;
  const data: Array<{ date: Date; open: number; high: number; low: number; close: number }> = [];
  let price = 88;
  for (let i = 0; i < 30; i++) {
    const weekday = new Date(start + i * day).getUTCDay();
    if (weekday === 0 || weekday === 6) continue;
    const drift = Math.cos(i / 4) * 2 + ((i * 7) % 5) - 2;
    const open = price;
    const close = Math.round((price + drift) * 100) / 100;
    data.push({
      date: new Date(start + i * day),
      open,
      high: Math.max(open, close) + 1.5,
      low: Math.min(open, close) - 1.2,
      close,
    });
    price = close;
  }
  return data;
}

Options

Options common to all series (name, showInLegend, tooltip.renderer, …) are covered in Common series options.

OptionTypeDefaultDescription
xFieldstringdate (Date / timestamp / string)
openFieldcloseFieldstringthe four OHLC keys
widthpresetchart size and theme in createFinancialChart
heightpresetchart size and theme in createFinancialChart
themepresetchart size and theme in createFinancialChart
containerpresetcontainer and data for createFinancialChart
datapresetcontainer and data for createFinancialChart
dateFieldpresetdate/OHLCpreset data fields
openFieldpresetdate/OHLCpreset data fields
highFieldpresetdate/OHLCpreset data fields
lowFieldpresetdate/OHLCpreset data fields
closeFieldpresetdate/OHLCpreset data fields
chartType'candlestick' | 'ohlc''candlestick'preset series type
titlepresetonpassed through to ChartOptions
navigatorpresetonpassed through to ChartOptions
zoompresetonpassed through to ChartOptions
annotationspresetonpassed through to ChartOptions
item.up.fillColorValuetheme greenfill of rising candles
item.down.fillColorValuetheme redfill of falling candles

Financial preset

A ready-made bundle in a single call — candlestick + ordinal-time + zoom + navigator + crosshair

  • context menu:
ts
import { Charts } from 'grafit-charts';

const chart = Charts.createFinancialChart({
  container,
  data, // [{ date, open, high, low, close }]
  title: 'CHRT / USD',
  chartType: 'candlestick', // | 'ohlc'
});

The keys can be overridden (dateField, openField, …), navigator: false / zoom: false disable those blocks, and annotations are passed through as-is.