demo D256
Fan chart in Angular
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 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-fan'; // opt in to the fan type
import { LatticeGridComponent, provideLattice } from '@toclocoinc/lattice-grid/angular';
@Component({
selector: 'app-root',
standalone: true,
imports: [LatticeGridComponent],
template:
'<div id="chart" style="height:340px"></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: '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 */],
};
ngAfterViewInit() {
createChart({ grid: this.gridRef.grid, container: '#chart', type: 'fan', x: 'month', y: 'actual', forecast: 'forecast', lower: 'lower', upper: 'upper', title: 'Actuals, then a forecast with its range' });
}
}
bootstrapApplication(AppComponent, {
providers: [provideLattice({ createGrid })],
});