demo D279
A trend line and a forecast in ESM
Draw a least-squares trend straight through the points and carry it on as a dashed forecast, with a vertical event marker flagging the day a change went live
trend: { method: 'linear', forecast: 8 }
This draws a least-squares trend straight through the points and carries it on as a dashed forecast, with a vertical marker flagging the day a change went live. It shows where a series is heading and lets you see whether an event bent the line.
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: 300px"></div>
<script type="module">
import { createChart } from '@toclocoinc/lattice-grid/modules/charts';
const grid = createGrid(document.getElementById('grid'), {
rowKey: 'id',
columns: [
{ field: 'day', title: 'Day', type: 'number' },
{ field: 'active', title: 'Active users', type: 'number', total: 'mean' },
],
rows, // one clean, sorted point per day: day, active
});
// trend fits a least-squares line through the points; forecast: 8 carries it
// eight steps past the last day as a dashed projection. It reads the grid's
// filtered rows, so narrowing the grid refits the trend.
createChart({
grid,
container: document.getElementById('chart'),
type: 'line',
x: 'day',
y: 'active',
legend: true,
trend: { method: 'linear', forecast: 8 },
title: 'The trend, projected ahead',
});
</script>