Lattice Grid Buy a licence

demo D228

Confidence intervals, charted in htmx

The mean lead time of each supplier with its 95% interval as a whisker, and a tile that narrows as you filter

grid.statistics.interval(col) · chart error: true

This grid charts each supplier's mean lead time with its 95 percent interval as a whisker, and a tile that narrows as you filter. It shows not just the average but how sure of it you can be, so a difference within the noise does not read as real.

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: 250px"></div>
<div id="tiles" style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 14px 0"></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="confidence-intervals-table" data-lattice-grid>
  <thead>
    <tr>
      <th data-field="supplier">Supplier</th>
      <th data-field="days">Days</th>
    </tr>
  </thead>
  <tbody>
    <tr data-id="O0"><td>Kestrel</td><td>3.1</td></tr>
    <tr data-id="O1"><td>Northgate</td><td>4.4</td></tr>
    <tr data-id="O2"><td>Selby</td><td>2.8</td></tr>
    <!-- the rest of the rows, rendered by your server -->
  </tbody>
</table>

<script type="module">
  import { hydrateTable, createStat } 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('confidence-intervals-table'), {
    toolPanel: { side: 'left', panels: ['filters', 'columns', 'statistics'] },
    columns: [
      { field: 'supplier', title: 'Supplier', filter: { type: 'set' } },
      { field: 'days', title: 'Lead time', type: 'number', format: { suffix: ' d', decimals: 1 }, total: 'avg' },
    ],
  });

  // interval() is the range the mean is pinned to, computed over the filtered
  // rows. The tile shows it under the value; ask for a proportion with
  // { kind: 'proportion' } and a rule for what counts as a success.
  const tile = () => document.getElementById('tiles').appendChild(document.createElement('div'));
  createStat({ grid, container: tile(), title: 'Mean lead time', of: 'days', fn: 'avg',
    interval: (value, grid) => grid.statistics.interval('days'), footer: '95% confidence interval' });

  // error: true draws each mean's 95% interval as a whisker, computed from the
  // readings behind the bar. The chart reads the same grid as the tile, so the
  // bars and the whiskers follow the filters.
  createChart({ grid, container: '#chart', type: 'bar', x: 'supplier', y: { col: 'days', fn: 'avg' },
    error: true, title: 'Mean lead time by supplier, with 95% confidence interval' });
</script>