demo D253
Series decomposition in Angular
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 Angular version. A standalone component takes the whole configuration through one config input, surfaces grid events as outputs, and exposes the live grid on a getter for anything the inputs do not cover.
The configuration
import { Component, ViewChild, AfterViewInit } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { createGrid } from '@toclocoinc/lattice-grid';
import '@toclocoinc/lattice-grid/css';
import { createChart } from '@toclocoinc/lattice-grid/modules/charts';
import '@toclocoinc/lattice-grid/modules/chart-decomposition'; // opt in to the decomposition type
import { LatticeGridComponent, provideLattice } from '@toclocoinc/lattice-grid/angular';
@Component({
selector: 'app-root',
standalone: true,
imports: [LatticeGridComponent],
template:
'<div id="chart" style="height:400px"></div>' +
'<lattice-grid [config]="grid" style="display:block;height:320px;margin-top:14px"></lattice-grid>',
})
export class AppComponent implements AfterViewInit {
@ViewChild(LatticeGridComponent) gridRef!: LatticeGridComponent;
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 */],
};
ngAfterViewInit() {
createChart({ grid: this.gridRef.grid, container: '#chart', type: 'decomposition', observed: 'observed', trend: 'trend', seasonal: 'seasonal', residual: 'residual', title: 'A series and its parts' });
}
}
bootstrapApplication(AppComponent, {
providers: [provideLattice({ createGrid })],
});