# Heatmap

A value by two cyclic dimensions, such as weekday by hour, as shaded cells.

- Family: charts
- Import: `import { Heatmap } from "@senvenli/react/charts";`
- Page: https://design.senvenli.com/docs/components/heatmap
- JSON: https://design.senvenli.com/docs/components/heatmap.json

## Example: Orders by weekday and hour

Two cyclic dimensions: the busy and the quiet times stand out.

```tsx
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" />;
}
```

## Examples

### A month by week

Days outside the month draw no cell; a day without data is hatched, never zero.

```tsx
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

- [calendar-heatmap](https://design.senvenli.com/docs/components/calendar-heatmap.md): The pattern is by date across weeks.
- [bar-chart](https://design.senvenli.com/docs/components/bar-chart.md): Only one cyclic dimension matters, such as the weekday.

## 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 | Required | Description |
| --- | --- | --- | --- | --- |
| title | `string` |  | no | What the chart shows ("Income and expenses"), over it; leave it out when a card or a heading already says so. |
| aria-label | `string` |  | no | Names the chart when it has no visible `title`. |
| period | `string` |  | no | The period it covers ("September 2026"). |
| isLoading | `boolean` |  | no |  |
| emptyState | `React.ReactNode` |  | no | Shown instead of the plot when there is no data: an `EmptyState size="small"` or text; "No data" by default. |
| rows | `readonly string[]` |  | yes | The rows, top to bottom ("Week 1" …, or the months). Names are unique: cells find their row by name. |
| columns | `readonly string[]` |  | yes | 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). |
| data | `readonly HeatmapCell[]` |  | yes | One entry per cell; a row and column with no entry draws no cell (a day outside the month). |
| rowHeader | `string` |  | no | 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]` |  | no | 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` | no |  |
| onCellPress | `(cell: HeatmapCell) => void` |  | no |  |

### Tokens it reads

`--ds-background-brand-subtle`, `--ds-background-neutral`, `--ds-background-neutral-pressed`, `--ds-background-selected-hovered`, `--ds-background-selected-pressed`, `--ds-border`, `--ds-border-bold`, `--ds-border-focused`, `--ds-chart-1`, `--ds-chart-2`, `--ds-chart-3`, `--ds-chart-4`, `--ds-chart-5`, `--ds-chart-neutral`, `--ds-icon-danger`, `--ds-icon-success`, `--ds-icon-warning`, `--ds-link`, `--ds-radius-medium`, `--ds-radius-small`, `--ds-radius-xsmall`, `--ds-shadow-overlay`, `--ds-space-050`, `--ds-space-075`, `--ds-space-100`, `--ds-space-150`, `--ds-space-200`, `--ds-space-300`, `--ds-space-400`, `--ds-surface-overlay`, `--ds-surface-raised`, `--ds-text`, `--ds-text-danger`, `--ds-text-subtle`, `--ds-text-subtlest`, `--ds-text-success`

## Related

- [calendar-heatmap](https://design.senvenli.com/docs/components/calendar-heatmap.md)
