# Heatmap

Heatmap for values across two dimensions: a weekday × hour matrix, a contribution calendar, a punch card, labelled cells and a correlation matrix.

- Category: Charts
- Page: https://wunderui.com/components/heatmap
- Tier: Core and Pro

## Install

Heatmap ships with WunderUI Core and Pro in the @wunderui/react package.

## Import

```tsx
import { HeatmapChart, HeatmapChartProps, HeatmapChartVariant } from "@wunderui/react"
```

## Minimal usage

Then use it:

```tsx
import { HeatmapChart } from "@wunderui/react/charts"

const matrix = [
  [4, 12, 30, 18],
  [6, 15, 34, 20],
  [2, 5, 9, 4],
]

export function TicketsByHour() {
  return (
    <HeatmapChart
      matrix={matrix}
      rowLabels={["Mon", "Tue", "Sat"]}
      columnLabels={["6:00", "12:00", "18:00", "24:00"]}
      label="Tickets by weekday and hour"
    />
  )
}
```

Expected result: You see a grid of three rows and four columns, darker where the value is higher.

## When to use

### Use Heatmap for

- A value for each row and column: weekday by hour, a contribution calendar
- A correlation matrix on a diverging scale
- A punch card, where the size of a circle replaces colour

### Use something else

- [Bubble Chart](https://wunderui.com/components/bubble-chart) for the relation between two measures
- [Bar Chart](https://wunderui.com/components/bar-chart) for values along one dimension
- [Treemap](https://wunderui.com/components/treemap) for parts of a hierarchy
- [Distribution Chart](https://wunderui.com/components/distribution-chart) for how one measure spreads

## Keyboard

The plot is focusable and the arrow keys walk the grid: left and right in a row, up and down between rows. The live region reads row, column and value (like Mon, 9am: 12), or no value for an empty cell.

| Key | Action |
|---|---|
| `Tab` or `Shift+Tab` | Moves focus to the plot and away from it. The plot is one tab stop; so is every legend badge. |
| `ArrowRight` or `ArrowLeft` | Moves to the next or previous cell in the row. The tooltip follows, and a live region announces the one you are on. The first press starts at the first cell (Left: the last one). |
| `ArrowDown` or `ArrowUp` | Moves to the cell below or above in the same column; a shorter row takes its nearest cell. |
| `Home` or `End` | Jumps to the first or last cell of the row. With Ctrl (Cmd on a Mac): to the first or last cell of the grid. |
| `Escape` | Clears the active point. |
| `Enter` or `Space` | On a legend badge of a ChartCard: switches its series off or on. The last visible series stays on. |

## Behavior

What the chart does on its own and what the page decides.

- **Matrix:** The matrix is a list of rows of values, with null for no data. Row and column labels name them, and the column tick setting thins the labels when there are many.
- **Colour:** Tint grows with value, and a null cell uses the muted colour, not a low value. The correlation matrix uses a diverging scale: blue for positive, red for negative.
- **Cell values:** The labelled heatmap and correlation matrix write the value in each cell, in a text colour that keeps contrast. When cells are too small, only the hovered or focused one shows its value.
- **Scale legend:** A Less to More strip sits under the grid, and you can hide it or add a caption such as 2,384 contributions in 2026.
- **Loading, empty and error:** The chart keeps its size while loading, empty or failed, so the card never changes height. Add a retry handler to show a Try again button on error.
- **Size:** The chart fills the width of its container, and you set the plot height. Text never scales: labels keep their size at every width.

## Motion

The enter sequence and hover follow the library's motion tokens.

- **Column wave:** Cells settle in column by column from left to right, the whole grid in about 1.1 s, the first time the chart is in view, after loading and when new data arrives. A parent re-render with the same values does not replay it. You can turn it off.
- **Hover:** The hovered or focused cell keeps its strength and the others dim to --chart-dim, with a short opacity transition.
- **Reduced motion:** With reduced motion the enter sequence is off and the chart appears at once. The tooltip, the hover dimming and every state still work.

## Anatomy

- `HeatmapChart`: Takes a matrix of rows by columns (null for no data) plus row and column labels. Options thin the column labels, set the colour scale or the tonal indigo palette, add a caption and name the two ends of the scale legend.
- `Plot`: The focusable region. Arrow keys walk the marks and the live region reads each one as the tooltip shows it.
- `Marks`: One rounded cell per value, arriving as a column wave from left to right. Strength grows with value (or one of five indigo steps) and a null cell uses the muted colour, not a low value. The hovered cell keeps its strength while every other cell steps back.
- `Cell value`: The number inside each cell on the labelled heatmap and correlation matrix, in a text colour that keeps contrast. When cells are too small, only the hovered or focused cell shows its value.
- `Scale legend`: The strip under the grid, Less to More by default (scaleLabels renames the ends, -1 to +1 on the correlation matrix, blue positive and red negative), plus a caption such as 2,384 contributions in 2026. Its width follows its labels.
- `Tooltip`: Row and column labels as the title, then the cell value.
- `Loading, empty and error`: Muted bars as the placeholder under the shimmer. A matrix with no numbers counts as empty, and you can reword the message with a custom title and description.
- `Data table and live region`: A table of every cell for screen readers.
- `Chart Scale Legend`

## Best practices

### When to use

- Use HeatmapChart for patterns across two categories, such as activity by weekday and hour. Use BarChart when only a few values are compared.

### Do

- Use one hue per measure (indigo by default, green on the calendar) so lightness is the only variable. Use diverging blue and red only for values around zero, like correlations.
- Use the labelled heatmap when people need the number, and the punch card when a cell has a count and a rate. Colour alone is a rough read.
- Pass null for missing data, not 0. A zero is a measurement and is drawn as the lowest step.

### Don't

- Don't compare two heatmaps with different maxima. Each one scales to its own largest value, so the same colour means different numbers.
- Don't go beyond about 7 by 24 cells without thinning the column labels. Dense labels overlap and the grid stops being readable.

## API reference

### HeatmapChart

| Prop | Type | Default | Description |
|---|---|---|---|
| columnLabels* | readonly string[] |  | Column labels; with `columnTickEvery` only every n-th is shown (calendar months, hours). |
| matrix* | readonly (readonly (number \| null)[])[] |  | Values row by row (rows × columns). `null` = no data. Correlation: −1…1. |
| rowLabels* | readonly string[] |  |  |
| activeIndex | number \| null |  | The active point (hovered or focused) as an index into `data`, to control it yourself. `null` shows none. |
| animate | boolean |  |  |
| animationKey | string \| number |  |  |
| caption | string |  | Text under the grid, e.g. "2,384 contributions in 2026". |
| className | string |  | Extra classes for the root element of the chart. |
| color | "indigo" \| "blue" \| "purple" \| "green" \| "orange" \| "pink" \| "yellow" \| "red" \| "grey" |  | Colour of the scale (default indigo; calendar green). Correlation uses blue / red. |
| columnTickEvery | number | 1 |  |
| defaultActiveIndex | number \| null |  | The point that is active at first, for an uncontrolled chart. It shows the tooltip without a pointer. |
| height | number |  |  |
| label | string |  |  |
| onActiveIndexChange | (index: number \| null) => void |  | Called with the index when the pointer or the arrow keys move to another point, and with `null` when they leave. Use it to show the hovered value in a headline. |
| onRetry | () => void |  | Shows a Try again button in the error state and calls this when it is pressed. |
| palette | "shade" \| "indigo" | "shade" | shade paints the scale colour at a strength that follows the value; indigo paints five tonal steps from indigo 200 (low) to 600 (high), with the text colour picked per step. The correlation matrix keeps blue and red. |
| scaleLabels | readonly [string, string] |  | The words at the two ends of the scale legend, such as Quiet and Busy. The correlation matrix defaults to -1 and +1. |
| showLegend | boolean | true | "Less ■■■■■ More" scale under the grid. Default true. |
| state | "ready" \| "loading" \| "empty" \| "error" |  |  |
| valueFormatter | ChartValueFormatter |  |  |
| variant | "matrix-heatmap" \| "calendar-heatmap" \| "punch-card" \| "labelled-heatmap" \| "correlation-matrix" | "matrix-heatmap" | Figma variant. Default `matrix-heatmap`. |
| width | number |  |  |

## Examples

### States

### Colour scale

## In context

### Support Tickets by Hour

When customers write in, by weekday and hour.

## For AI agents

`get_component("heatmap")`

Hand your agent this page as Markdown or the WunderUI MCP server, not a screenshot.
