Lattice Grid Buy a licence

demo D265

Waffle chart in ESM

A hundred squares filled in the proportion each part holds, an easier whole to read than a pie

type: 'waffle', x, y

This fills a hundred squares in the proportion each part holds, an easier whole to read than a pie. It shows a percentage split as counted squares, so 'about a third' reads as a clear block rather than a slice angle.

Building…
Loading a live grid…

This is the ES module version. The grid is imported straight from a CDN as a module, the same configuration as the vanilla tab without a global script tag, so it drops into any bundler or a bare module script.

The configuration

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

<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';
  import '@toclocoinc/lattice-grid/modules/chart-waffle';  // opt in to the waffle type

  const grid = 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.
  // A hundred squares stand for the whole; each part takes as many as its share.
  createChart({
    grid,
    container: document.getElementById('chart'),
    type: 'waffle',
    x: 'status',
    y: 'charge',
    title: 'Share of charge by status',
  });
</script>