demo D256
Fan chart: JavaScript Data Grid Demo
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.
Loading a live grid…
The configuration
<link rel="stylesheet" href="https://cdn.latticegrid.dev/lattice-grid@1.108.1/lattice-grid.min.css">
<script src="https://cdn.latticegrid.dev/lattice-grid@1.108.1/lattice-grid.min.js"></script>
<div id="grid" style="height: 320px"></div>
<div id="chart" style="height: 340px"></div>
<script type="module">
import { createChart } from '@toclocoinc/lattice-grid/modules/charts';
import '@toclocoinc/lattice-grid/modules/chart-fan'; // opt in to the fan type
const grid = LatticeGrid.createGrid(document.getElementById('grid'), {
rowKey: 'id',
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' },
],
rows, // actuals then a forecast band: month, actual, forecast, lower, upper
});
// A solid line for the actuals, then a band from lower to upper that widens
// the further ahead the forecast reaches.
createChart({
grid,
container: document.getElementById('chart'),
type: 'fan',
x: 'month',
y: 'actual',
forecast: 'forecast',
lower: 'lower',
upper: 'upper',
title: 'Actuals, then a forecast with its range',
});
</script>