demo D177
Data labels in ESM
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.
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.latticegrid.dev/lattice-grid@1.107.0/lattice-grid.min.css">
<div id="grid" style="height: 340px"></div>
<div id="chart" style="height: 320px"></div>
<script type="module">
import { createGrid } from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/lattice-grid.esm.min.js';
import { createChart } from '@toclocoinc/lattice-grid/modules/charts';
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.
// labels: true writes the value beside each mark; a label that would overlap
// one already placed is dropped rather than drawn over it.
createChart({
grid,
container: document.getElementById('chart'),
type: 'bar',
x: 'region',
y: 'charge',
labels: true,
title: 'Monthly charge by region',
});
</script>