demo D169
Values on a map in ESM
Continents and countries from ISO codes
type: 'geomap', code, y
This plots values on a map of continents and countries, keyed by ISO codes on your rows. It turns a table of places into a map you read at a glance, so regional patterns stand out geographically rather than as rows.
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.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.71.0/lattice-grid.min.css">
<div id="grid" style="height: 300px"></div>
<div id="chart" style="height: 380px; margin-top: 12px"></div>
<script type="module">
import { createChart } from '@toclocoinc/lattice-grid/modules/charts';
// A geometry pack registers itself on import; shapes: { pack: id } names it.
import { pack } from '@toclocoinc/lattice-grid/modules/geo-world-110m';
const grid = createGrid(document.getElementById('grid'), {
rowKey: 'id',
columns: [
{ field: 'country', title: 'ISO code', layout: { pin: 'start', width: 140 } },
{ field: 'revenue', title: 'Revenue', type: 'number', format: { style: 'currency', currency: 'USD' }, total: 'sum' },
],
// One deliberately unmatched code, so the map reports it rather than
// dropping it silently.
rows, // country revenue: id, country (ISO alpha-2, or ZZ), revenue
});
createChart({
grid,
container: document.getElementById('chart'),
type: 'geomap',
code: 'country',
y: { col: 'revenue', fn: 'sum' },
shapes: { pack: pack.id },
title: 'Revenue by country',
});
</script>