Lattice Grid Buy a licence

demo D172

Chart events: JavaScript Data Grid Demo

Click, hover and legend, wired to your app

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

This wires a chart's click, hover and legend interactions to your own application code. It lets a chart drive whatever your app needs when a reader interacts with it, beyond the grid, from a small set of events.

Building…
Loading a live grid…

The configuration

<link rel="stylesheet" href="https://cdn.latticegrid.dev/lattice-grid@1.103.2/lattice-grid.min.css">
<script src="https://cdn.latticegrid.dev/lattice-grid@1.103.2/lattice-grid.min.js"></script>

<div id="chart" style="height: 260px"></div>
<div id="grid" style="height: 340px; margin-top: 14px"></div>

<script type="module">
  import { createChart } from '@toclocoinc/lattice-grid/modules/charts';

  const grid = LatticeGrid.createGrid(document.getElementById('grid'), {
    rowKey: 'id',
    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' },
    ],
    rows,  // circuit records
  });

  const chart = createChart({ grid, container: document.getElementById('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));
</script>