Polar Area Chart for Incidents by Month
If you are an incident manager, the question you bring to every quarterly review is which months were the bad ones, and whether the bad months come round at the same time each year. A column of twelve numbers hides that. You want to see the season.
A polar area chart answers it. The twelve months sit around a circle, each month a wedge of the same width, and the area of each wedge grows with that month’s incident count. A bad quarter shows as a bulge on one side of the circle. The chart above is bound to the grid beneath it, one row per month and team, so filtering the rows redraws the wedges. Filter the Team column and see the shape for just that team.
Why a polar area chart and not a bar chart
Months are a cycle: December sits next to January. A bar chart cuts the cycle open and puts a gap where the year turns, so a bad stretch from November into February looks like two separate problems. Around a circle the stretch is one bulge. The radius is drawn so the wedge’s area, which is what the eye reads, follows the count.
The chart over a grid
Name the category column in x and the measure in y. Each team has its own row for a month, and the chart adds up the rows the grid has left after its filters, so a filtered grid gives a filtered chart. Polar area 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-polararea';
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const teams = ['Platform', 'Payments', 'Support'];
const counts = [6, 5, 7, 6, 5, 4, 9, 14, 16, 12, 7, 6];
const rows = months.flatMap((month, m) => teams.map((team, t) => ({
id: m * 3 + t + 1, month, team, incidents: Math.max(1, counts[m] - t * 2),
})));
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: 'month', title: 'Month' },
{ field: 'team', title: 'Team', filter: { type: 'set' } },
{ field: 'incidents', title: 'Incidents', type: 'number' },
],
});
createChart({ grid, container: chartEl, type: 'polarArea', x: 'month', y: 'incidents',
title: 'Incidents by month' });
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-polararea';
const LatticeGrid = createLatticeGrid({ React, createGrid });
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const teams = ['Platform', 'Payments', 'Support'];
const counts = [6, 5, 7, 6, 5, 4, 9, 14, 16, 12, 7, 6];
const rows = months.flatMap((month, m) => teams.map((team, t) => ({
id: m * 3 + t + 1, month, team, incidents: Math.max(1, counts[m] - t * 2),
})));
const columns = [
{ field: 'month', title: 'Month' },
{ field: 'team', title: 'Team', filter: { type: 'set' } },
{ field: 'incidents', title: 'Incidents', type: 'number' },
];
export function IncidentsByMonth() {
const gridRef = useRef(null);
const chartRef = useRef(null);
useEffect(() => {
const chart = createChart({ grid: gridRef.current.grid, container: chartRef.current,
type: 'polarArea', x: 'month', y: 'incidents', title: 'Incidents by month' });
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 | 'polarArea' here, one wedge per x category. |
x |
string | The category column, one wedge for each value. |
y |
string | The measure column, which sets how large each wedge’s area is. |
title |
string | Drawn above the plot. |
polar.scale |
'linear' |
Unset, the radius is area-true. 'linear' draws it straight from the value. |
Reading the bulge
Look first at the longest wedges and at whether their neighbours are long too. In the example, the incidents gather in late summer and ease off by winter, which tells you where to put on-call cover and change freezes. Filter the Team column to see whether one team carries the bulge or all of them do, and clear the filter to see the total again. Because the radius follows the square root of the count, a month with four times the incidents reaches twice as far, so compare areas rather than lengths. If you would rather have the radius drawn straight from the value, set polar: { scale: 'linear' }, at the cost of exaggerating the big months.
Next
See the polar area beside the other circular charts in the polar 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.