Lattice Grid

blog

OHLC Chart for Commodity Prices

Building…
Loading a live grid…

If you buy raw materials, the question you bring to every purchase is whether today is a good day to buy. Is the price near the bottom of its recent range, or has it already run up, and how wide does it swing in a day?

An OHLC chart answers that. Each day is one bar: a vertical line from the day’s low to its high, a tick to the left at the open and a tick to the right at the close. The chart above is bound to the grid beneath it, one row per trading day, so filtering the rows redraws the bars. Filter the Week column to the last two weeks and see where the price sits in its recent range.

Why OHLC and not a line chart

A line chart of closing prices throws away the day. It cannot show that the price touched a low and recovered, or that a quiet close hid a wide swing. The bars keep all four readings, and a run of short bars against a run of long ones tells you how much the price is moving before you commit to an order.

The chart over a grid

The date column is the position along the axis, and the four measures are the open, high, low and close, in that order. Each bar is coloured up or down by whether the close finished above the open. OHLC is built into the charts module, so there is nothing else to register. Here is the example in plain JavaScript, with sample rows inline in place of your own.

import { createGrid } from '@toclocoinc/lattice-grid';
import '@toclocoinc/lattice-grid/css';
import { createChart } from '@toclocoinc/lattice-grid/modules/charts';

const rows = [
  ['2026-10-01', 9189, 9297, 9135, 9243], ['2026-10-02', 9243, 9293, 9185, 9248],
  ['2026-10-05', 9248, 9350, 9188, 9312], ['2026-10-06', 9312, 9363, 9245, 9280],
  ['2026-10-07', 9280, 9317, 9193, 9259], ['2026-10-08', 9259, 9333, 9192, 9315],
].map(([date, open, high, low, close]) => ({ date, open, high, low, close }));

const gridEl = document.createElement('div');
const chartEl = document.createElement('div');
gridEl.style.height = '240px';
chartEl.style.height = '420px';
document.body.append(gridEl, chartEl);

const grid = createGrid(gridEl, {
  rowKey: 'date', rows,
  columns: [
    { field: 'date', title: 'Date', filter: { type: 'set' } },
    { field: 'open', title: 'Open', type: 'number' },
    { field: 'high', title: 'High', type: 'number' },
    { field: 'low', title: 'Low', type: 'number' },
    { field: 'close', title: 'Close', type: 'number' },
  ],
});
createChart({ grid, container: chartEl, type: 'ohlc', x: 'date',
  measures: ['open', 'high', 'low', 'close'], title: 'Copper, dollars a tonne' });

The same thing in React

The React adapter is a factory, so you build the component once at module scope. The ref’s grid is the real grid, which is what the chart binds to.

import React, { useEffect, useRef } from 'react';
import { createGrid } from '@toclocoinc/lattice-grid';
import '@toclocoinc/lattice-grid/css';
import { createLatticeGrid } from '@toclocoinc/lattice-grid/modules/react';
import { createChart } from '@toclocoinc/lattice-grid/modules/charts';

const LatticeGrid = createLatticeGrid({ React, createGrid });
const rows = [
  ['2026-10-01', 9189, 9297, 9135, 9243], ['2026-10-02', 9243, 9293, 9185, 9248],
  ['2026-10-05', 9248, 9350, 9188, 9312], ['2026-10-06', 9312, 9363, 9245, 9280],
  ['2026-10-07', 9280, 9317, 9193, 9259], ['2026-10-08', 9259, 9333, 9192, 9315],
].map(([date, open, high, low, close]) => ({ date, open, high, low, close }));
const columns = [
  { field: 'date', title: 'Date', filter: { type: 'set' } },
  { field: 'open', title: 'Open', type: 'number' },
  { field: 'high', title: 'High', type: 'number' },
  { field: 'low', title: 'Low', type: 'number' },
  { field: 'close', title: 'Close', type: 'number' },
];

export function CommodityOhlc() {
  const gridRef = useRef(null);
  const chartRef = useRef(null);
  useEffect(() => {
    const chart = createChart({ grid: gridRef.current.grid, container: chartRef.current,
      type: 'ohlc', x: 'date', measures: ['open', 'high', 'low', 'close'] });
    return () => chart.destroy();
  }, []);
  return (<>
    <LatticeGrid ref={gridRef} rowKey="date" columns={columns} rows={rows} style={{ height: 240 }} />
    <div ref={chartRef} style={{ height: 360 }} />
  </>);
}

The options used

These are the rows of the charts reference for the options in the listings above.

Option Type What it does
grid Grid Required. The grid to read.
container Element or string Required. Where to draw.
type string 'ohlc' here, one bar per row.
x string The date column, one bar each.
measures string[] The open, high, low and close columns, in that order.
title string Drawn above the plot.

Reading the range

Look first at where the latest close sits between the lowest low and the highest high of the weeks you have filtered. A close near the bottom of the range, after bars that keep recovering from their lows, is the kind of day a buyer waits for. A close at the top, on long bars, says the price is stretched. In the example the price climbs to its highest high in the second week and then holds a narrower band below it, so filtering to the last three weeks shows a calmer market than the whole six.

Next

See the OHLC bars beside the other specialist charts in the specialist family demo, read the full list of chart types on the charts page, or follow the how-to for a chart that follows the grid.

Read next

  • Candlestick Chart of a Daily Price Series

    Bind a candlestick chart to a grid of daily prices and read open, high, low and close with volume beneath. Filter the rows and the chart redraws.

  • Funnel Chart for a Sales Pipeline

    Bind a funnel chart to a grid of pipeline counts: leads, qualified, proposal, won. Filter the rows by region to redraw the drop at each stage.

  • Gauge Chart of Warehouse Utilisation

    Bind a gauge chart to a grid of warehouse zones and read utilisation against its bands. Filter the rows and the needle moves.

All posts RSS