demo D173
Brushing a time range in Angular
Drag a range on the chart and the grid narrows to it
brush: true
This lets you drag a range across a time chart and narrows the grid to it. It gives a reader a quick way to focus on a period, selecting the window on the chart and reading the matching rows in the grid.
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 } 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 { LatticeGridComponent, provideLattice } from '@toclocoinc/lattice-grid/angular';
const columns = [
{ field: 'date', title: 'Date', type: 'dateString', layout: { pin: 'start', width: 150 } },
{ field: 'price', title: 'Price', type: 'number', format: { decimals: 2 } },
{ field: 'volume', title: 'Volume', type: 'number', format: { notation: 'compact' } },
];
const rows = [/* one row a day: date, price, volume */];
@Component({
selector: 'app-root',
standalone: true,
imports: [LatticeGridComponent],
template:
'<div id="chart" style="height:300px"></div>' +
'<lattice-grid [config]="grid" (grid-ready)="onGridReady()" style="display:block;height:320px;margin-top:14px"></lattice-grid>',
})
export class AppComponent {
@ViewChild(LatticeGridComponent) gridRef!: LatticeGridComponent;
grid = {
rowKey: 'id',
columns: columns,
rows: rows,
};
// The grid is created once the view has rendered, so the live instance
// arrives on grid-ready rather than in ngAfterViewInit.
onGridReady() {
const grid = this.gridRef.grid;
// brush: true lets you drag a range across the chart, and the grid narrows
// to those days. The chart reads the live grid through the ref, so both
// views move on one gesture.
createChart({ grid, container: '#chart', type: 'line', x: 'date', y: 'price', brush: true,
title: 'Price over time (brush to filter)' });
}
}
bootstrapApplication(AppComponent, {
providers: [provideLattice({ createGrid })],
});