demo D253
Series decomposition in ESM
Read a series as its trend, its seasonal rhythm and the residual, stacked to compare
type: 'decomposition', trend, seasonal, residual
This reads a series as its trend, its seasonal rhythm and the residual, stacked to compare. It pulls apart what is a long-term direction, what is a repeating pattern, and what is noise, so each can be judged on its own.
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: 400px"></div>
<script type="module">
import { createChart } from '@toclocoinc/lattice-grid/modules/charts';
import '@toclocoinc/lattice-grid/modules/chart-decomposition'; // opt in to the decomposition type
const grid = createGrid(document.getElementById('grid'), {
rowKey: 'id',
columns: [
{ field: 'month', title: 'Month' },
{ field: 'observed', title: 'Observed', type: 'number' },
{ field: 'trend', title: 'Trend', type: 'number' },
{ field: 'seasonal', title: 'Seasonal', type: 'number' },
{ field: 'residual', title: 'Residual', type: 'number' },
],
rows, // a series split into its parts: month, observed, trend, seasonal, residual
});
// Each part is its own column; the chart stacks them on one x axis.
createChart({
grid,
container: document.getElementById('chart'),
type: 'decomposition',
observed: 'observed',
trend: 'trend',
seasonal: 'seasonal',
residual: 'residual',
title: 'A series and its parts',
});
</script>