demo D205
Density over a histogram
A kernel density estimate over the bars, so binning and data separate
curve: true, buckets
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' } },
];
const rows = [/* trading records, one per instrument */];
function App() {
const gridRef = React.useRef(null);
React.useEffect(() => {
const grid = gridRef.current.grid;
// The bars depend on where the bin edges fall; the density curve has no
// edges, so laying one over the other separates the shape of the data from
// the choice of buckets. The chart reads the live grid through the ref.
createChart({ grid, container: '#chart', type: 'histogram', y: 'price',
buckets: 20, curve: true, title: 'Price, with a density curve' });
}, []);
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>