demo D204
Statistical process control in React
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 React version. The grid mounts through the createLatticeGrid adapter, which takes its configuration as ordinary props and hands back the live grid through a ref. The grid below is the same one every other tab runs.
The configuration
<link rel="stylesheet" href="https://cdn.latticegrid.dev/lattice-grid@1.107.0/lattice-grid.min.css">
<div id="app"></div>
<script type="module">
import React from 'https://esm.sh/react@18';
import { createRoot } from 'https://esm.sh/react-dom@18/client';
import { createGrid } from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/lattice-grid.esm.min.js';
import { createLatticeReact } from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/modules/react.esm.min.js';
import { createChart } from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/modules/charts.esm.min.js';
const { LatticeGrid, LatticeChart } = createLatticeReact({ React, createGrid, createChart });
const 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 } },
];
const rows = [/* machined bore measurements */];
function App() {
const [grid, setGrid] = React.useState(null);
// baseline sets the control limits over the first readings. The chart
// reads the live grid, so it follows every filter.
return (
<>
{grid && <LatticeChart grid={grid} type="control" y="bore" baseline={20} style={{ height: '340px' }} />}
<LatticeGrid
rowKey="id"
columns={columns}
rows={rows}
onGridReady={setGrid}
style={{ height: '320px', marginTop: '14px' }}
/>
</>
);
}
createRoot(document.getElementById('app')).render(<App />);
</script>