Examples

Busy hours

Preview
Support tickets by hourTuesday and Thursday afternoons are busiest.
Use the arrow keys to move between data points, Home and End to jump to the first and last.
Example.tsx
import { Heatmap } from '@reactloom/charts';

const days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'];
const hours = ['08–10', '10–12', '12–14', '14–16', '16–18'];
const data = days.flatMap((day, d) => hours.map((band, h) => ({ day, band, tickets: ((d + 2) * (h + 3) * 7) % 47 + 3 })));

export default function Example() {
  return <Heatmap title="Support tickets by hour" description="Tuesday and Thursday afternoons are busiest." data={data} x="band" y="day" value="tickets" showValues />;
}

Cohort retention

A fixed 0\u2013100% scale with domain.

Preview
Customer retention by cohortHeatmap of 4 rows by 6 columns, values from 0% to 100%. Highest: Jan, Month 1: 100%.
Use the arrow keys to move between data points, Home and End to jump to the first and last.
Customer retention by cohort (data)
CategoryMonth 1Month 2Month 3Month 4Month 5Month 6
Jan100%71%60%49%38%27%
Feb100%73%62%51%40%—
Mar100%75%64%53%——
Apr100%77%66%———
Example.tsx
import { Heatmap } from '@reactloom/charts';

// A cohort retention grid with a fixed 0–100% scale.
const cohorts = ['Jan', 'Feb', 'Mar', 'Apr'];
const data = cohorts.flatMap((cohort, c) => Array.from({ length: 6 - c }, (_, m) => ({ cohort, month: `Month ${m + 1}`, kept: m === 0 ? 1 : Math.max(0.2, 0.82 - m * 0.11 + c * 0.02) })));

export default function Example() {
  return <Heatmap title="Customer retention by cohort" data={data} x="month" y="cohort" value="kept" domain={[0, 1]} valueFormat={{ style: 'percent' }} table="visible" />;
}

API reference

Heatmap props
PropTypeDefault
datarequired
Row[]—
x · yrequired
Column and row of each cell.
key or (row) => string—
valuerequired
key or (row) => number—
domain
Fix the colour scale.
[min, max]—
showValues
Write values in large cells.
booleanfalse
titlerequired
Names the figure.
string—
description
The takeaway; a factual summary is generated when omitted.
ReactNode—
table
The data table alternative.
'toggle' | 'visible' | 'none''toggle'
height · valueFormat · formatValue · messages
As on the other charts.
—

Customization

Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.

State attributes

Target these in your CSS to style states without depending on class names.

AttributeValues
[data-active]present when on

Theme tokens it reads

--pl-color-bg-surface --pl-color-fg-default --pl-color-fg-muted --pl-color-fg-on-accent --pl-font-size-xs --pl-radius-full

Accessibility

  • The chart is a figure named by its title and described by a summary; the drawing is hidden from assistive technology.
  • The plot is one tab stop: arrow keys move between items and each is announced; the data table gives every value.
  • Colour is never the only cue: each cell's value is announced and in the table.
Keyboard interactions
KeyAction
← → ↑ ↓Move between cells in two dimensions
Home / EndFirst / last cell

Usage guidelines

Do

  • Pick a fixed domain when charts are compared side by side.

Don’t

  • Don't use a diverging meaning on a sequential colour scale.