Lattice Grid Buy a licence

demo D265

Waffle chart in React

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 React version. The grid mounts through the createLatticeGrid adapter, which takes its configuration as ordinary props and hands back the live grid through a ref. The grid below is the same one every other tab runs.

The configuration

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

<div id="app"></div>

<script type="module">
  import React from 'https://esm.sh/react@18';
  import { createRoot } from 'https://esm.sh/react-dom@18/client';
  import { createGrid } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.71.0/lattice-grid.esm.min.js';
  import { createLatticeReact } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.71.0/modules/react.esm.min.js';
  import { createChart } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.71.0/modules/charts.esm.min.js';
  import 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.71.0/modules/chart-waffle.esm.min.js';  // opt in to the waffle type

  const { LatticeGrid, LatticeChart } = createLatticeReact({ React, createGrid, createChart });

  const 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' },
  ];

  const rows = [/* circuits: region, status, bandwidth, utilisation, charge */];

  function App() {
    const [grid, setGrid] = React.useState(null);

    return (
      <>
        {grid && (
          <LatticeChart grid={grid} type="waffle" x="status" y="charge" title="Share of charge by status" style={{ height: '320px' }} />
        )}
        <LatticeGrid
          rowKey="id"
          columns={columns}
          rows={rows}
          onGridReady={setGrid}
          style={{ height: '340px', marginTop: '14px' }}
        />
      </>
    );
  }

  createRoot(document.getElementById('app')).render(<App />);
</script>