Lattice Grid Buy a licence

demo D172

Chart events

Click, hover and legend, wired to your app

chart.on('click' | 'hover' | 'legend')

Building…
Loading a live grid…

The configuration

import * as ng from '@angular/core';
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 createLatticeGrid from '@toclocoinc/lattice-grid/modules/angular';

const { LatticeGridComponent } = createLatticeGrid({ ng, createGrid });

const columns = [
  { field: 'circuit', title: 'Circuit', layout: { width: 180 } },
  { field: 'region', title: 'Region', filter: { type: 'set' } },
  { field: 'status', title: 'Status', filter: { type: 'set' } },
  { field: 'bandwidth', title: 'Bandwidth', type: 'number' },
  { field: 'charge', title: 'Monthly charge', type: 'number',
    format: { style: 'currency', currency: 'GBP' }, total: 'sum' },
];

const rows = [/* circuit records */];



@Component({
  selector: 'app-root',
  standalone: true,
  imports: [LatticeGridComponent],
  template:
    '<div id="chart" style="height:260px"></div>' +
    '<lattice-grid [config]="grid" style="display:block;height:340px;margin-top:14px"></lattice-grid>',
})
export class AppComponent implements AfterViewInit {
  @ViewChild(LatticeGridComponent) gridRef!: LatticeGridComponent;

  grid = {
    rowKey: 'id',
    columns: columns,
    rows: rows,
  };

  ngAfterViewInit() {
    const grid = this.gridRef.grid;
    const chart = createChart({ grid, container: '#chart', type: 'pie', x: 'status', y: 'charge',
      title: 'Charge by status' });

    // Every chart event hands you one flat payload. Read the parts you want off
    // it: category and value on a click, category on a hover, label and hidden
    // on a legend toggle.
    chart.on('click',  (e) => console.log('click',  e.category, e.value));
    chart.on('hover',  (e) => console.log('hover',  e.category));
    chart.on('legend', (e) => console.log('legend', e.label, e.hidden));
  }
}

bootstrapApplication(AppComponent);