Lattice Grid Buy a licence

demo D214

Candlestick in htmx

Open, high, low and close, one row a day

type: 'candlestick', measures: [open, high, low, close]

This draws a candlestick chart, one candle a day from open, high, low and close, with a price axis on the right, zoom and pan, and a drawing rail for trend lines, channels, Fibonacci retracements and measuring a range. It shows a market's daily range and direction in the form traders read, straight from the grid's rows.

Building…
Loading a live grid…

This is the htmx version. A server-rendered table is upgraded in place, so the page is readable before any script runs and gains the full grid when the module loads, which suits a progressively enhanced app.

The configuration

<link rel="stylesheet" href="https://cdn.latticegrid.dev/lattice-grid@1.107.0/lattice-grid.min.css">

<div id="chart" style="height: 320px"></div>
<!-- A real, server-rendered table: readable with JavaScript off. data-field on
     each header names the column that cell becomes, and data-id on each row is
     the key the grid carries it under. -->
<table id="chart-types-candlestick-table" data-lattice-grid>
  <thead>
    <tr>
      <th data-field="day">Day</th>
      <th data-field="open">Open</th>
      <th data-field="high">High</th>
      <th data-field="low">Low</th>
      <th data-field="close">Close</th>
    </tr>
  </thead>
  <tbody>
    <tr data-id="1"><td>2026-01-02</td><td>100</td><td>101.2</td><td>99.3</td><td>100.8</td></tr>
    <tr data-id="2"><td>2026-01-05</td><td>100.8</td><td>102.4</td><td>100.1</td><td>102</td></tr>
    <tr data-id="3"><td>2026-01-06</td><td>102</td><td>102.3</td><td>100.6</td><td>100.9</td></tr>
    <!-- the rest of the rows, rendered by your server -->
  </tbody>
</table>

<script type="module">
  import { hydrateTable } from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/modules/htmx.esm.min.js';
  import { createChart } from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/modules/charts.esm.min.js';

  // The markup carries the rows; a server-rendered table's column types are
  // declared in the config hydrateTable takes. The grid replaces the table
  // where it stood.
  const grid = hydrateTable(document.getElementById('chart-types-candlestick-table'), {
    columns: [
      { field: 'day', title: 'Day', type: 'date', layout: { width: 120 } },
      { field: 'open',  title: 'Open',  type: 'number', format: { decimals: 2 } },
      { field: 'high',  title: 'High',  type: 'number', format: { decimals: 2 } },
      { field: 'low',   title: 'Low',   type: 'number', format: { decimals: 2 } },
      { field: 'close', title: 'Close', type: 'number', format: { decimals: 2 } },
    ],
  });

  // Candlestick takes four measures, in open, high, low, close order.
  createChart({ grid, container: '#chart', type: 'candlestick', x: 'day',
    measures: [{ col: 'open' }, { col: 'high' }, { col: 'low' }, { col: 'close' }] });
</script>