demo D256
Fan chart in ESM
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.
This is the ES module version. The grid is imported straight from a CDN as a module, the same configuration as the vanilla tab without a global script tag, so it drops into any bundler or a bare module script.
The configuration
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.71.0/lattice-grid.min.css">
<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 = 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>