Lattice Grid Buy a licence

demo D254

Diverging bars in ESM

Gains one way and losses the other off a shared centre, so direction reads before size

type: 'diverging', x, y

This draws gains one way and losses the other off a shared centre line, so direction reads before size. It suits data that goes both ways, sentiment or change, where whether a value is positive or negative is the first thing to see.

Building…
Loading a live grid…

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: 320px"></div>
<div id="chart" style="height: 340px"></div>

<script type="module">
  import { createChart } from '@toclocoinc/lattice-grid/modules/charts';
  import '@toclocoinc/lattice-grid/modules/chart-diverging';  // opt in to the diverging type

  const grid = createGrid(document.getElementById('grid'), {
    rowKey: 'id',
    columns: [
      { field: 'category', title: 'Line of business' },
      { field: 'net', title: 'Net change', type: 'number', total: 'sum' },
    ],
    rows,  // one row a category: category, net (positive or negative)
  });

  // Bars grow one way for a gain, the other for a loss, off one centre line.
  createChart({
    grid,
    container: document.getElementById('chart'),
    type: 'diverging',
    x: 'category',
    y: 'net',
    title: 'Net change by line of business',
  });
</script>