Lattice Grid Buy a licence

demo D205

Density over a histogram in React

A kernel density estimate over the bars, so binning and data separate

curve: true, buckets

This draws a kernel density estimate over a histogram of the same column, so the smooth shape and the binning are kept separate. It shows the underlying distribution without being misled by the choice of bin widths.

Building…
Loading a live grid…

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: '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 [grid, setGrid] = React.useState(null);

    // 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.
    return (
      <>
        {grid && <LatticeChart grid={grid} type="histogram" y="price" buckets={20} curve title="Price, with a density curve" style={{ height: '340px' }} />}
        <LatticeGrid
          rowKey="id"
          columns={columns}
          rows={rows}
          onGridReady={setGrid}
          style={{ height: '320px', marginTop: '14px' }}
        />
      </>
    );
  }

  createRoot(document.getElementById('app')).render(<App />);
</script>