demo D163
Line, area, bar and scatter
The cartesian types, one dataset
type: 'line' · 'step' · 'area' · 'bar' · 'combo' · 'pareto'
Loading a live grid…
The configuration
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.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.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.0/lattice-grid.esm.min.js';
import createLatticeGrid from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.0/modules/react.esm.min.js';
import { createChart } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.0/modules/charts.esm.min.js';
const LatticeGrid = createLatticeGrid({ React, createGrid });
const columns = [
{ field: 'circuit', title: 'Circuit', layout: { width: 180 } },
{ field: 'region', title: 'Region', filter: { type: 'set' } },
{ field: 'status', title: 'Status', filter: { type: 'set' } },
{ field: 'bandwidth', title: 'Bandwidth', type: 'number' },
{ field: 'charge', title: 'Monthly charge', type: 'number',
format: { style: 'currency', currency: 'GBP' }, total: 'sum' },
];
const rows = [/* circuit records */];
function App() {
const gridRef = React.useRef(null);
// The cartesian family, each reading the live grid through the ref, so a
// filter or an edit redraws every chart together.
React.useEffect(() => {
const grid = gridRef.current.grid;
createChart({ grid, container: '#line', type: 'line', x: 'region', y: 'charge' });
createChart({ grid, container: '#step', type: 'step', x: 'region', y: 'charge' });
createChart({ grid, container: '#area', type: 'area', x: 'region', y: 'charge' });
// rangeArea draws the min-to-max band of y at each x.
createChart({ grid, container: '#rangeArea', type: 'rangeArea', x: 'region', y: 'charge' });
createChart({ grid, container: '#bar', type: 'bar', x: 'region', y: 'charge' });
createChart({ grid, container: '#horizontalBar', type: 'horizontalBar', x: 'region', y: 'charge' });
createChart({ grid, container: '#scatter', type: 'scatter', x: 'bandwidth', y: 'charge' });
createChart({ grid, container: '#bubble', type: 'bubble', x: 'bandwidth', y: 'charge', size: 'charge' });
// combo mixes marks and two axes, here bars of charge and a line of bandwidth.
createChart({ grid, container: '#combo', type: 'combo', x: 'region',
measures: [{ col: 'charge', fn: 'sum', type: 'bar', axis: 'left' },
{ col: 'bandwidth', fn: 'mean', type: 'line', axis: 'right' }] });
// pareto sorts the bars and draws the cumulative line.
createChart({ grid, container: '#pareto', type: 'pareto', x: 'status', y: 'charge' });
}, []);
return (
<>
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: '14px', height: '210px' }}>
<div id="line" />
<div id="step" />
<div id="area" />
<div id="rangeArea" />
<div id="bar" />
<div id="horizontalBar" />
<div id="scatter" />
<div id="bubble" />
<div id="combo" />
<div id="pareto" />
</div>
<LatticeGrid
ref={gridRef}
rowKey="id"
columns={columns}
rows={rows}
style={{ height: '340px', marginTop: '14px' }}
/>
</>
);
}
createRoot(document.getElementById('app')).render(<App />);
</script>