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

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.0/lattice-grid.min.css">

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

<script type="module">
  import { createGrid } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.0/modules/htmx.esm.js';
  import { createChart } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.0/modules/charts.esm.min.js';

  const grid = 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,  // an array of circuit records
  });

  const chart = createChart({ grid, container: '#chart', type: 'pie', x: 'status', y: 'charge' });

  // Every chart event carries a flat payload naming the mark under the pointer.
  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>