Lattice Grid Buy a licence

demo D177

Data labels in Svelte

Values beside the marks, or left to the axis

labels: true

This shows values printed beside the marks, or left to the axis, as a choice. It lets you put the exact figure on the chart where precision matters, or keep it clean and let the axis carry the scale.

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 withEl;
  let withoutEl;

  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. Both charts read
    // that one grid; labels writes the value beside each mark, and turned off the
    // axis carries the scale instead.
    onGrid: (grid) => {
      createChart({ grid, container: withEl,    type: 'bar', x: 'region', y: 'charge', labels: true });
      createChart({ grid, container: withoutEl, type: 'bar', x: 'region', y: 'charge', labels: false });
    },
  };
</script>

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

<div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; height: 260px">
  <div bind:this={withEl}></div>
  <div bind:this={withoutEl}></div>
</div>
<div use:lattice={config} style="height: 340px; margin-top: 14px"></div>