import { Heatmap } from "@senvenli/react/charts";
const DAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
const HOURS = ["8 AM", "10 AM", "12 PM", "2 PM", "4 PM", "6 PM", "8 PM"];
// A lunch and an evening peak, weaker on weekends: fixed arithmetic, no random values.
const HOUR_LOAD = [12, 26, 48, 31, 29, 54, 37];
const DAY_LOAD = [1, 0.9, 1.1, 1.2, 1.4, 0.7, 0.5];
const ORDERS = DAYS.flatMap((row, day) => HOURS.map((column, hour) => ({ row, column, value: Math.round(HOUR_LOAD[hour]! * DAY_LOAD[day]!) })));
export default function Example() {
return <Heatmap title="Orders by weekday and hour" period="March 2026" rows={DAYS} columns={HOURS} data={ORDERS} rowHeader="Day" />;
}import { Heatmap } from "@senvenli/react/charts";Examples
A month by week
Days outside the month draw no cell; a day without data is hatched, never zero.import { Heatmap } from "@senvenli/react/charts";
const WEEKS = ["Week 1", "Week 2", "Week 3", "Week 4", "Week 5"];
const WEEKDAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
const usd = new Intl.NumberFormat("en", { style: "currency", currency: "USD", maximumFractionDigits: 0 });
// March 2026 starts on a Sunday. The 17th has no figure (the register was offline): `null`, not 0.
const REVENUE = Array.from({ length: 31 }, (_, index) => {
const day = index + 1;
const weekday = index % 7;
const value = day === 17 ? null : 1800 + ((day * 37) % 11) * 240 + (weekday === 5 || weekday === 6 ? 1900 : 0);
return { row: WEEKS[Math.floor(index / 7)]!, column: WEEKDAYS[weekday]!, value, label: `March ${day}` };
});
export default function Example() {
return (
<Heatmap
title="Daily revenue"
period="March 2026"
rows={WEEKS}
columns={WEEKDAYS}
data={REVENUE}
rowHeader="Week"
thresholds={[1, 2500, 3500, 5000]}
valueFormatter={usd.format}
/>
);
}Guidelines
When to use it
- Finding busy and quiet times.
Use something else when
- The pattern is by date across weeks. Calendar heatmap
- Only one cyclic dimension matters, such as the weekday. Bar chart
Accessibility
Built in
- A "Show as table" button shows the same data as a table, which screen readers get by default.
You provide
- A title that says what the figure is.
API reference
Heatmap
| Prop | Type | Default | Description |
|---|---|---|---|
title | string | – | What the chart shows ("Income and expenses"), over it; leave it out when a card or a heading already says so. |
aria-label | string | – | Names the chart when it has no visible |
period | string | – | The period it covers ("September 2026"). |
isLoading | boolean | – | |
emptyState | React.ReactNode | – | Shown instead of the plot when there is no data: an |
rowsRequired | readonly string[] | – | The rows, top to bottom ("Week 1" …, or the months). Names are unique: cells find their row by name. |
columnsRequired | readonly string[] | – | The columns, from the inline start (the weekdays, or the weeks). Names are unique, as for |
dataRequired | readonly HeatmapCell[] | – | One entry per cell; a row and column with no entry draws no cell (a day outside the month). |
rowHeader | string | – | The row headers' name ("Week"), on the data table's first header and the grid's corner; "Period" by default. |
thresholds | readonly [number, number, number, number] | – | Four strictly ascending lower bounds of the four intensity steps; from the positive values' quartiles by default. Bounds out of order still count each bound a value reaches, so the steps no longer follow the values (the chart warns). |
valueFormatter | ChartValueFormatter | plain | |
onCellPress | (cell: HeatmapCell) => void | – |
titlestringWhat the chart shows ("Income and expenses"), over it; leave it out when a card or a heading already says so.
aria-labelstringNames the chart when it has no visible
title.periodstringThe period it covers ("September 2026").
isLoadingbooleanemptyStateReact.ReactNodeShown instead of the plot when there is no data: an
EmptyState size="small"or text; "No data" by default.rowsRequiredreadonly string[]The rows, top to bottom ("Week 1" …, or the months). Names are unique: cells find their row by name.
columnsRequiredreadonly string[]The columns, from the inline start (the weekdays, or the weeks). Names are unique, as for
rows: a name given twice draws both, but every cell of that name lands in the first (the chart warns).dataRequiredreadonly HeatmapCell[]One entry per cell; a row and column with no entry draws no cell (a day outside the month).
rowHeaderstringThe row headers' name ("Week"), on the data table's first header and the grid's corner; "Period" by default.
thresholdsreadonly [number, number, number, number]Four strictly ascending lower bounds of the four intensity steps; from the positive values' quartiles by default. Bounds out of order still count each bound a value reaches, so the steps no longer follow the values (the chart warns).
valueFormatterChartValueFormatterDefaultplainonCellPress(cell: HeatmapCell) => void