Lattice Grid Buy a licence

demo D256

Fan chart in React

An actual line that opens into a forecast band, widening the further ahead it reaches

type: 'fan', x, y, forecast, lower, upper

This draws an actual line that opens into a forecast band, widening the further ahead it reaches. It shows a projection with its growing uncertainty, so a reader sees not just the estimate but how confident it is.

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.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.71.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.71.0/lattice-grid.esm.min.js';
  import { createLatticeReact } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.71.0/modules/react.esm.min.js';
  import { createChart } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.71.0/modules/charts.esm.min.js';
  import 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.71.0/modules/chart-fan.esm.min.js';  // opt in to the fan type

  const { LatticeGrid, LatticeChart } = createLatticeReact({ React, createGrid, createChart });

  const columns = [
      { field: 'month', title: 'Month' },
      { field: 'actual', title: 'Actual', type: 'number' },
      { field: 'forecast', title: 'Forecast', type: 'number' },
      { field: 'lower', title: 'Lower', type: 'number' },
      { field: 'upper', title: 'Upper', type: 'number' },
  ];

  const rows = [/* actuals then a forecast band: month, actual, forecast, lower, upper */];

  function App() {
    const [grid, setGrid] = React.useState(null);

    return (
      <>
        {grid && (
          <LatticeChart grid={grid} type="fan" x="month" y="actual" forecast="forecast" lower="lower" upper="upper" title="Actuals, then a forecast with its range" style={{ height: '340px' }} />
        )}
        <LatticeGrid
          rowKey="id"
          columns={columns}
          rows={rows}
          onGridReady={setGrid}
          style={{ height: '320px', marginTop: '14px' }}
        />
      </>
    );
  }

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