demo D206
A fitted line
Least squares per series, with R², agreeing with the API
fit: true
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: 'symbol', title: 'Symbol', layout: { pin: 'start', width: 120 } },
{ field: 'desk', title: 'Desk', filter: { type: 'set' } },
{ field: 'price', title: 'Price', type: 'number', format: { decimals: 4 } },
{ field: 'volume', title: 'Volume', type: 'number', format: { notation: 'compact' } },
{ field: 'notional', title: 'Notional', type: 'number',
format: { style: 'currency', currency: 'USD' }, total: 'sum' },
];
const rows = [/* trading records, one per instrument */];
function App() {
const gridRef = React.useRef(null);
React.useEffect(() => {
const grid = gridRef.current.grid;
// fit draws a least-squares line through the points, per series, with its
// R2 beside it. The chart reads the live grid through the ref, so the fit
// recomputes over whatever the filters leave.
createChart({ grid, container: '#chart', type: 'scatter', x: 'volume', y: 'notional',
fit: true, title: 'Notional against volume, fitted' });
}, []);
return (
<>
<div id="chart" style={{ height: '340px' }} />
<LatticeGrid
ref={gridRef}
rowKey="id"
columns={columns}
rows={rows}
style={{ height: '320px', marginTop: '14px' }}
/>
</>
);
}
createRoot(document.getElementById('app')).render(<App />);
</script>