Lattice Grid Buy a licence

demo D174

Small multiples in Svelte

One chart per category, on a shared scale

multiples: col

This draws one small chart per category on a shared scale, laid out as a grid of charts. It lets you compare many groups at once without overlaying them, so each category reads on its own but against the same yardstick.

Building…
Loading a live grid…

This is the Svelte version. A use action attaches the grid to a plain element, so no framework runtime is passed in and the component stays small, while the configuration is ordinary Svelte state.

The configuration

<script>
  import { createGrid } from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/lattice-grid.esm.min.js';
  import createLatticeAction from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/modules/svelte.esm.min.js';
  import { createChart } from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/modules/charts.esm.min.js';

  const lattice = createLatticeAction({ createGrid });

  let chartEl;

  const config = {
    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
    // onGrid hands over the live grid the moment it is created. multiples draws
    // one small chart per distinct value of that column, on a shared scale so
    // they compare, and all follow the grid's filters.
    onGrid: (grid) => {
      createChart({ grid, container: chartEl, type: 'bar', x: 'status', y: 'charge', multiples: 'region' });
    },
  };
</script>

<svelte:head>
  <link rel="stylesheet" href="https://cdn.latticegrid.dev/lattice-grid@1.107.0/lattice-grid.min.css">
</svelte:head>

<div bind:this={chartEl} style="height: 300px"></div>
<div use:lattice={config} style="height: 340px; margin-top: 14px"></div>