demo D204
Statistical process control in htmx
Control limits against spec limits, which are not the same thing
type: 'control', y, baseline
This draws a statistical process control chart with control limits set against spec limits, which are not the same thing. It shows when a process is drifting out of its own normal behaviour, distinct from whether it meets the spec, so you catch a change early.
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: 340px"></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="control-chart-table" data-lattice-grid>
<thead>
<tr>
<th data-field="part">Part</th>
<th data-field="bore">Bore</th>
</tr>
</thead>
<tbody>
<tr data-id="1"><td>P001</td><td>10</td></tr>
<tr data-id="2"><td>P002</td><td>10.079</td></tr>
<tr data-id="3"><td>P003</td><td>9.98</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('control-chart-table'), {
columns: [
{ field: 'part', title: 'Part', layout: { width: 110 } },
// The spec declares the tolerance; the control chart reads it.
{ field: 'bore', title: 'Bore', type: 'number',
spec: { lower: 9.5, upper: 10.8, target: 10 } },
],
});
// baseline sets the control limits over the first readings, then every point
// is judged against them.
createChart({ grid, container: '#chart', type: 'control', y: 'bore', baseline: 20 });
</script>