Lattice Grid

blog

Pyramid Chart for a Content Audience

Building…
Loading a live grid…

If you lead content, the question you carry into every planning meeting is how much of your reach turns into customers. Of everyone who sees what you publish, how many engage, how many subscribe, and how many buy, and which channel does the best job of moving people up?

A pyramid chart answers that. Each layer of the audience is a slice of one triangle, with customers at the apex and reach at the base, so the narrowing from the base to the point is the whole story at a glance. The chart above is bound to the grid beneath it, one row per channel and layer, so filtering the rows redraws the pyramid. Filter the Channel column to one channel and see only its audience.

Why a pyramid and not a funnel

A funnel and a pyramid read the same rows, and a funnel is the right picture for steps people pass through in order, such as a sales pipeline. An audience is different: it is a standing population that sits in layers, and the many at the bottom are what support the few at the top. A pyramid shows that, and with the area option on, each slice’s area is proportional to its count, so the shape is not exaggerated.

The chart over a grid

The layer column is the slice and the count column is its size. Rows for the same layer are summed, so the grid can hold one row per channel and the pyramid still shows the total for the channels left after filtering. The first layer in the rows is the apex, so list the narrowest layer first. Pyramid is an opt-in chart type, so you import its module once 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-pyramid';

const layers = ['Customers', 'Subscribers', 'Engaged', 'Reach'];
const counts = { Search: [140, 1900, 5200, 48000], Social: [60, 1400, 4100, 82000], Newsletter: [220, 2600, 3300, 9000] };
const rows = Object.entries(counts).flatMap(([channel, list]) =>
  list.map((count, i) => ({ id: `${channel}-${layers[i]}`, channel, layer: layers[i], count })));

const gridEl = document.createElement('div');
const chartEl = document.createElement('div');
gridEl.style.height = '240px';
chartEl.style.height = '420px';
document.body.append(gridEl, chartEl);

const grid = createGrid(gridEl, {
  rowKey: 'id', rows,
  columns: [
    { field: 'channel', title: 'Channel', filter: { type: 'set' } },
    { field: 'layer', title: 'Layer', filter: { type: 'set' } },
    { field: 'count', title: 'Count', type: 'number' },
  ],
});
createChart({ grid, container: chartEl, type: 'pyramid', x: 'layer', y: 'count',
  title: 'Content audience', stages: { area: true } });

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-pyramid';

const LatticeGrid = createLatticeGrid({ React, createGrid });
const layers = ['Customers', 'Subscribers', 'Engaged', 'Reach'];
const counts = { Search: [140, 1900, 5200, 48000], Social: [60, 1400, 4100, 82000], Newsletter: [220, 2600, 3300, 9000] };
const rows = Object.entries(counts).flatMap(([channel, list]) =>
  list.map((count, i) => ({ id: `${channel}-${layers[i]}`, channel, layer: layers[i], count })));
const columns = [
  { field: 'channel', title: 'Channel', filter: { type: 'set' } },
  { field: 'layer', title: 'Layer' },
  { field: 'count', title: 'Count', type: 'number' },
];

export function AudiencePyramid() {
  const gridRef = useRef(null);
  const chartRef = useRef(null);
  useEffect(() => {
    const chart = createChart({ grid: gridRef.current.grid, container: chartRef.current,
      type: 'pyramid', x: 'layer', y: 'count', title: 'Content audience', stages: { area: true } });
    return () => chart.destroy();
  }, []);
  return (<>
    <LatticeGrid ref={gridRef} rowKey="id" columns={columns} rows={rows} style={{ height: 200 }} />
    <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 'pyramid' here, one slice per layer.
x string The layer column, one slice each.
y string The measure column, here the count at that layer.
title string Drawn above the plot.
stages object The pyramid’s options: inverted, area, gap and labels. area: true makes a slice’s area proportional to its value.

Reading the audience

Look first at how thin the apex is against the base, because that is the share of your reach that becomes customers. In the example, social has by far the widest base and the thinnest apex, while the newsletter has a small base and the thickest apex for its size. Filter the Channel column to compare a channel against the whole, and clear it to see the total again.

Next

See the pyramid 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

  • 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.

  • Funnel Chart for a Sales Pipeline

    Bind a funnel chart to a grid of pipeline counts: leads, qualified, proposal, won. Filter the rows by region to redraw the drop at each stage.

All posts RSS