Lattice Grid Buy a licence

demo D162

Your first chart: JavaScript Data Grid Demo

A chart from the grid's own data in six lines

createChart({ grid, container, type, x, y })

This draws a chart from the grid's own data in six lines: hand it the grid, a container, a type, and the fields for the axes. It is the smallest start for charting, so you can see a live chart wired to real rows before learning anything more.

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="grid" style="height: 340px"></div>
<div id="chart" style="height: 320px"></div>

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

  const grid = LatticeGrid.createGrid(document.getElementById('grid'), {
    rowKey: 'id',
    columns: [
      { field: 'region', title: 'Region', filter: { type: 'set' } },
      { field: 'status', title: 'Status', filter: { type: 'set' } },
      { field: 'bandwidth', title: 'Bandwidth', type: 'number' },
      { field: 'utilisation', title: 'Utilisation', type: 'number', format: { decimals: 1, suffix: '%' } },
      { field: 'charge', title: 'Monthly charge', type: 'number',
        format: { style: 'currency', currency: 'GBP' }, total: 'sum' },
    ],
    rows,  // circuits: region, status, bandwidth, utilisation, charge
  });

  // A chart reads the grid's filtered rows and redraws when the grid changes.
  createChart({
    grid,
    container: document.getElementById('chart'),
    type: 'bar',
    x: 'region',   // the category column
    y: 'charge',   // the measure; a categorical chart reduces it for you
    title: 'Monthly charge by region',
  });
</script>