Charts
Heatmap
Values across two categories as a colour grid — load by weekday and hour, retention by cohort.
import '@reactloom/charts/styles.css';
import { Heatmap } from '@reactloom/charts';Examples
Busy hours
Use the arrow keys to move between data points, Home and End to jump to the first and last.
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.
Use the arrow keys to move between data points, Home and End to jump to the first and last.
| Category | Month 1 | Month 2 | Month 3 | Month 4 | Month 5 | Month 6 |
|---|---|---|---|---|---|---|
| Jan | 100% | 71% | 60% | 49% | 38% | 27% |
| Feb | 100% | 73% | 62% | 51% | 40% | — |
| Mar | 100% | 75% | 64% | 53% | — | — |
| Apr | 100% | 77% | 66% | — | — | — |
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
| Prop | Type | Default |
|---|---|---|
datarequired | Row[] | — |
x · yrequiredColumn and row of each cell. | key or (row) => string | — |
valuerequired | key or (row) => number | — |
domainFix the colour scale. | [min, max] | — |
showValuesWrite values in large cells. | boolean | false |
titlerequiredNames the figure. | string | — |
descriptionThe takeaway; a factual summary is generated when omitted. | ReactNode | — |
tableThe data table alternative. | 'toggle' | 'visible' | 'none' | 'toggle' |
height · valueFormat · formatValue · messagesAs 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.
| Attribute | Values |
|---|---|
[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.
| Key | Action |
|---|---|
| ← → ↑ ↓ | Move between cells in two dimensions |
| Home / End | First / 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.