Lattice Grid Buy a licence

demo D175

Colour schemes in htmx

Built-in palettes, the default colour-blind safe

scheme: 'default' · 'bright' · 'earth' · 'mono'

This shows the built-in colour palettes, with the default chosen to be colour-blind safe. It lets you match a chart to your product's palette while keeping the categories distinguishable for every reader.

Building…
Loading a live grid…

This is the htmx version. A server-rendered table is upgraded in place, so the page is readable before any script runs and gains the full grid when the module loads, which suits a progressively enhanced app.

The configuration

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

<div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; height: 210px">
  <div id="default"></div>
  <div id="bright"></div>
  <div id="earth"></div>
  <div id="mono"></div>
</div>
<!-- A real, server-rendered table: readable with JavaScript off. data-field on
     each header names the column that cell becomes, and data-id on each row is
     the key the grid carries it under. -->
<table id="chart-colour-schemes-table" data-lattice-grid>
  <thead>
    <tr>
      <th data-field="circuit">Circuit</th>
      <th data-field="region">Region</th>
      <th data-field="status">Status</th>
      <th data-field="bandwidth">Bandwidth</th>
      <th data-field="charge">Monthly charge</th>
    </tr>
  </thead>
  <tbody>
    <tr data-id="0"><td>DFB-EDI-100000</td><td>Edinburgh</td><td>live</td><td>100</td><td>94.88</td></tr>
    <tr data-id="1"><td>MPL-BIR-100001</td><td>Birmingham</td><td>provisioning</td><td>10000</td><td>4324.6</td></tr>
    <tr data-id="2"><td>DFB-LON-100002</td><td>London</td><td>live</td><td>2000</td><td>1031.02</td></tr>
    <!-- the rest of the rows, rendered by your server -->
  </tbody>
</table>

<script type="module">
  import { hydrateTable } from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/modules/htmx.esm.min.js';
  import { createChart } from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/modules/charts.esm.min.js';

  // The markup carries the rows; a server-rendered table's column types are
  // declared in the config hydrateTable takes. The grid replaces the table
  // where it stood.
  const grid = hydrateTable(document.getElementById('chart-colour-schemes-table'), {
    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' },
    ],
  });

  // The default scheme is the colour-blind-safe palette.
  createChart({ grid, container: '#default', type: 'pie', x: 'region', y: 'charge', scheme: 'default' });
  createChart({ grid, container: '#bright',  type: 'pie', x: 'region', y: 'charge', scheme: 'bright' });
  createChart({ grid, container: '#earth',   type: 'pie', x: 'region', y: 'charge', scheme: 'earth' });
  createChart({ grid, container: '#mono',    type: 'pie', x: 'region', y: 'charge', scheme: 'mono' });
</script>