Lattice Grid

blog

Pictorial Chart of Fleet by Vehicle Type

Building…
Loading a live grid…

If you manage a fleet, the question you bring to every review is what you are actually running. How many vans against trucks, how many cars, and does the mix still match the work the depots take on?

A pictorial chart answers that with a picture. Each vehicle type is a row of icons, and one icon stands for ten vehicles, with the last one clipped to the fraction left over. The chart above is bound to the grid beneath it, one row per depot and type, so filtering the rows redraws the icons. Filter the Depot column to one depot and see what it runs.

Why pictorial and not a bar chart

A bar chart gives you the exact length and leaves you to translate it. A row of icons is a count you can feel at a glance, which suits a report read by people who want the mix and not the axis. When the audience is a depot manager or a finance review, “about fifteen vans’ worth against four lorries’ worth” lands faster than a scale.

The chart over a grid

The x option is the category and y the measure, and the chart totals the rows behind each category, so a depot filter shrinks every row of icons together. In repeat mode the unit is what one icon stands for, and shape is an SVG path, here a simple van. The pictorial chart is its own small module, so import it after the charts module. Here is the example in plain JavaScript, with sample rows inline in place of your own.

import { createGrid } from '@toclocoinc/lattice-grid';
import '@toclocoinc/lattice-grid/css';
import { createChart } from '@toclocoinc/lattice-grid/modules/charts';
import '@toclocoinc/lattice-grid/modules/chart-pictorial';

const rows = [
  { id: 1, depot: 'North', type: 'Van', count: 34 },
  { id: 2, depot: 'North', type: 'Pickup', count: 12 },
  { id: 3, depot: 'North', type: 'Rigid truck', count: 18 },
  { id: 4, depot: 'South', type: 'Van', count: 28 },
  { id: 5, depot: 'South', type: 'Pickup', count: 9 },
  { id: 6, depot: 'South', type: 'Rigid truck', count: 14 },
];
const gridEl = document.createElement('div');
const chartEl = document.createElement('div');
gridEl.style.height = '240px';
chartEl.style.height = '360px';
document.body.append(gridEl, chartEl);

const grid = createGrid(gridEl, {
  rowKey: 'id', rows,
  columns: [
    { field: 'depot', title: 'Depot', filter: { type: 'set' } },
    { field: 'type', title: 'Vehicle type', filter: { type: 'set' } },
    { field: 'count', title: 'Vehicles', type: 'number' },
  ],
});
createChart({ grid, container: chartEl, type: 'pictorial', x: 'type', y: 'count',
  pictorial: { mode: 'repeat', shape: 'M0 2H12V4H16L20 7V10H0Z', unit: 10 },
  title: 'Fleet by vehicle type, one icon is ten vehicles' });

The same thing in React

The React adapter is a factory, so you build the component once at module scope. The ref’s grid is the real grid, which is what the chart binds to.

import React, { useEffect, useRef } from 'react';
import { createGrid } from '@toclocoinc/lattice-grid';
import '@toclocoinc/lattice-grid/css';
import { createLatticeGrid } from '@toclocoinc/lattice-grid/modules/react';
import { createChart } from '@toclocoinc/lattice-grid/modules/charts';
import '@toclocoinc/lattice-grid/modules/chart-pictorial';

const LatticeGrid = createLatticeGrid({ React, createGrid });
const rows = [
  { id: 1, depot: 'North', type: 'Van', count: 34 },
  { id: 2, depot: 'North', type: 'Pickup', count: 12 },
  { id: 3, depot: 'North', type: 'Rigid truck', count: 18 },
  { id: 4, depot: 'South', type: 'Van', count: 28 },
  { id: 5, depot: 'South', type: 'Pickup', count: 9 },
  { id: 6, depot: 'South', type: 'Rigid truck', count: 14 },
];
const columns = [
  { field: 'depot', title: 'Depot', filter: { type: 'set' } },
  { field: 'type', title: 'Vehicle type', filter: { type: 'set' } },
  { field: 'count', title: 'Vehicles', type: 'number' },
];

export function FleetPictorial() {
  const gridRef = useRef(null);
  const chartRef = useRef(null);
  useEffect(() => {
    const chart = createChart({ grid: gridRef.current.grid, container: chartRef.current,
      type: 'pictorial', x: 'type', y: 'count',
      pictorial: { mode: 'repeat', shape: 'M0 2H12V4H16L20 7V10H0Z', unit: 10 } });
    return () => chart.destroy();
  }, []);
  return (<>
    <LatticeGrid ref={gridRef} rowKey="id" columns={columns} rows={rows} style={{ height: 240 }} />
    <div ref={chartRef} style={{ height: 360 }} />
  </>);
}

The options used

These are the rows of the charts reference for the options in the listings above.

Option Type What it does
grid Grid Required. The grid to read.
container Element or string Required. Where to draw.
type string 'pictorial' here, a row of icons per category.
x string The category column, here the vehicle type.
y string The measure column, here the number of vehicles.
pictorial.mode 'fill' or 'repeat' 'repeat' draws a row of icons per category.
pictorial.shape string An icon name from the grid’s registry or an SVG path string.
pictorial.unit number What one icon stands for in 'repeat' mode.
title string Drawn above the plot.

Reading the rows of icons

Look first at the longest row, then at how the others compare with it. In the example the vans outnumber every other type, and the articulated lorries are the shortest row. Filter to the Docklands depot and the picture turns over: rigid trucks lead there and cars nearly vanish. That is the mix a depot is built for, and a row that looks wrong against the work it takes on is where to start asking questions.

Next

See the pictorial chart beside the other specialist charts in the specialist family demo, read the full list of chart types on the charts page, or follow the how-to for a chart that follows the grid.

Read next

  • Pyramid Chart for a Content Audience

    Bind a pyramid chart to a grid of audience counts: reach, engaged, subscribers, customers. Filter the rows by channel to redraw the layers.

  • OHLC Chart for Commodity Prices

    Bind an OHLC chart to a grid of daily open, high, low and close prices. Filter the rows by week to redraw the bars and time a purchase.

  • Candlestick Chart of a Daily Price Series

    Bind a candlestick chart to a grid of daily prices and read open, high, low and close with volume beneath. Filter the rows and the chart redraws.

All posts RSS