demo D178
Charts with no grid on screen in Svelte
The data engine driving charts on its own
createHeadlessGrid
This drives charts from the data engine alone, with no grid on screen. It shows that the charting and the data model do not need a visible table, so you can chart a dataset headlessly.
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 { createHeadlessGrid } from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/lattice-grid.esm.min.js';
import { createChart } from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/modules/charts.esm.min.js';
import { onMount } from 'svelte';
let byRegionEl;
let byStatusEl;
let distributionEl;
const config = {
rowKey: 'id',
columns: [
{ field: 'circuit', title: 'Circuit', layout: { width: 180 } },
{ field: 'region', title: 'Region', filter: { type: 'set' } },
{ field: 'status', title: 'Status', filter: { type: 'set' } },
{ field: 'bandwidth', title: 'Bandwidth', type: 'number' },
{ field: 'charge', title: 'Monthly charge', type: 'number',
format: { style: 'currency', currency: 'GBP' }, total: 'sum' },
],
rows, // an array of circuit records
};
// No visible table: createHeadlessGrid is the data engine on its own, and
// every chart draws from it, with the same follow behaviour.
onMount(() => {
const grid = createHeadlessGrid(config);
createChart({ grid, container: byRegionEl, type: 'bar', x: 'region', y: 'charge', title: 'by region' });
createChart({ grid, container: byStatusEl, type: 'donut', x: 'status', y: 'charge', title: 'by status' });
createChart({ grid, container: distributionEl, type: 'histogram', y: 'charge', title: 'distribution' });
return () => grid.destroy();
});
</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(3, 1fr); gap: 14px; height: 260px">
<div bind:this={byRegionEl}></div>
<div bind:this={byStatusEl}></div>
<div bind:this={distributionEl}></div>
</div>