> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> To set up Hatchmark for a user, follow https://hatchmark.dev/docs/get-started/agent-setup.md. Inside a Hatchmark project, prefer `hatchmark docs`: it prints the docs of the installed version.

# Heatmap

> The heatmap block shades a grid of one column's values by another's, such as orders by weekday and hour, by a metric or by a category column.

One column's values down the side and another's across the top, each cell coloured by a metric or
by a category: orders by weekday and hour, revenue by region and product, or the year each country
joined each club.

```yaml theme={null}
type: heatmap
title: Evenings are busiest, and weekends peak at midday
y: weekday
x: hour
value: orders
```

[Live preview of the heatmap component](https://components.hatchmark.dev/components/heatmap/?embed\&theme=light)

The preview above is the live component gallery. [Open it full size](https://components.hatchmark.dev/#/heatmap) to switch between desktop and phone widths.

## Options

| Field | Type | Default | Description |
| - | - | - | - |
| `x` | column | required | Column across the top: one column of cells per value. |
| `y` | column | required | Column down the side: one row of cells per value. Readers can pick a row. |
| `value` | metric or column | required | A metric shades each cell on a scale; a text or yes/no column colours it by category. |
| `limit` | 1–100 | `50` | Rows kept, in order; the card says how many more there are. |
| `span`, `title`, `id` | | | As for [every block](/docs/reference/dashboards.md#blocks). A heatmap takes no `height`. |

When `value` names both a metric and a column, the metric wins.

## Examples

### Weekday by hour

With `weekday` and `hour` columns in the data, `y: weekday` and `x: hour` with a count or sum
metric shows when things happen. Weekdays run from Monday and hours from 0.

### Who belongs to which club

A table with one row per country and club, and a metric that takes the earliest year:

```yaml theme={null}
label: Member since
type: aggregate
table: memberships
aggregate: min
column: joined_year
```

```yaml theme={null}
type: heatmap
title: No two clubs have the same members
y: member
x: club_name
value: member_since
```

Each cell prints the year a country joined a club. The earliest years take the strongest shades, so
the founding members stand out, and a cell for a club a country is not in is hatched.

### Status by category

```yaml theme={null}
type: heatmap
title: Most services are live in North America first
y: service
x: region
value: status
```

`status` is a text column of the same source as `service` and `region`, so each cell takes the
colour of its status, with a key of statuses below.

## How the numbers work

* Every cell is the metric over the rows that have its pair of values, read in one query with the
  page's period and filters. A cell never adds up other cells, so averages, distinct counts and
  ratios are right in each cell.
* A cell with no rows is hatched and reads "No data". A cell whose rows give the metric no value,
  or hold no category, reads "No value".
* Rows and columns whose values are numbers, dates, weekday names or month names keep that order.
  Others go by how many cells they fill, then by their own value over all their cells (the metric
  read for the whole row or column, not a sum of its cells), strongest shade first, then by name.
* The scale has 3 to 7 classes between round numbers from the lowest to the highest cell. Values on
  both sides of zero get a diverging scale around zero.
* An aggregate `min` or `max` whose every cell is a whole number from 1000 to 2999 reads as a year:
  it prints as `1958`, not `1,958`. With `min`, earlier years take the strongest shades.
* A category heatmap counts the rows of each category in each cell. The cell takes the category with
  the most rows; when its rows disagree, the tooltip says how many hold another one and the build
  warns (HM4097). Categories are keyed most cells first, with up to eight colours; past eight, the
  seven largest keep theirs and the rest share a grey Other.
* Select filters narrow the rows before the cells are formed. A category heatmap reads its column
  over all time; a metric heatmap reads the page's period.

## Behavior

* Cells print their value when the metric is a number; category cells are colour only, with the
  category in the tooltip and in the screen reader's cell text.
* Hover, tap or focus a cell for a tooltip with its row, column and value. Arrow keys move between
  cells. On a narrow card the tooltip sits above the grid instead.
* Picking a row name filters the page's other blocks to that value, as on a bar list or table.
* The grid is a table, so screen readers read each cell with its row and column names. The row names
  stay in view while the grid scrolls sideways. The card shows every row, and the header row stays at
  the top of the window, below the page's bar on a phone, while the page scrolls past a tall grid. On
  a phone, column names longer than four characters turn upright.
* Light and dark themes use the theme's sequential, diverging and categorical colours, with the
  number in each cell drawn in the ink that reads on its fill.

## Checks

| Code | When |
| - | - |
| HM2003 | `value` is neither a metric nor a column of a source that has `x` and `y`. |
| HM2018 | A table the metric reads has no `x` or `y` column. |
| HM2072 | Several sources have the `x`, `y` and `value` columns. |
| HM2073 | The `value` column holds numbers; define a metric over it instead. |
| HM4097 | The rows of some cells hold several categories; each cell takes the most common one. |
| HM3007 | `x` and `y` name the same column, or `value` repeats one of them. |
| HM2024 | `span` is under 3; the heatmap is drawn 3 columns wide. |

`hatchmark explain <code>` explains a check and how to fix it.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.