Skip to content
EspañolEnglish
All components (283)

Heatmap

Data · HeatmapChart · .amset-heatmap

What it is and when to use it

A grid of cells whose colour says how much: orders by day and hour, usage per week. It is for seeing patterns at a glance; the exact figures are in each cell's tooltip and in the table.

When to use it

  • Two axes with categories and a value at each crossing.
  • values has one list per row. null means no data, and it is drawn differently: it is not the same as zero.

When not to

  • A single series over time: LineChart.
  • Comparing few categories: BarChart.

Keyboard: Tab takes you to the grid (a single tab stop) and the arrows move from cell to cell; Home and End go to the ends of the row, and Escape leaves. A spoken notice says each cell.

Accessibility: the grid is an image (role="img") with a written summary, and underneath goes a real table. Colour is not alone: a cell with no data has a pattern, and each value can be read in the tooltip and the table.

Fine-tuning: --amset-heatmap-cell is the minimum cell size, --amset-heatmap-name the width of the names and --amset-heatmap-tone the colour.

What it looks like

Orders by day and hour

Week of 2 to 6 March

Peak hour

Viernes, 18-20 h

34 orders in that slot

Use the arrow keys to move through the values, Home and End to jump to the first and last, and Escape to leave.
Orders by day and hour
SlotMonTueWedThuFri
8-1046385
10-121215101714
12-141821162427
14-1691181316
16-1814no data121821
18-202219253034

<Card title="Orders by day and hour" subtitle="Week of 2 to 6 March">
<Stat label="Peak hour" value="Friday, 6-8 pm" detail="34 orders in that slot" tone="accent" />
<HeatmapChart
  label="Orders by day and hour"
  rows={["8-10", "10-12", "12-14", "14-16", "16-18", "18-20"]}
  columns={["Mon", "Tue", "Wed", "Thu", "Fri"]}
  values={pedidosPorFranja}
  rowName="Slot"
/>
</Card>

Props

Import it with import { HeatmapChart } from '@amset/ui'. Required props are marked.

PropTypeWhat it does
columnsrequiredreadonly string[]What goes on top: the hours.
labelrequiredstringWhat is being measured. Required: a chart without a title does not inform.
rowsrequiredreadonly string[]What goes on the left: the days of the week.
valuesrequiredreadonly (readonly (number | null)[])[]One list per row, with one value per column. `null` means no data, which is not the same as zero.
classNamestringMerged with the library classes; it does not replace them.
errorReactNodeThe data has not arrived: it says so in the place of the drawing, with what is passed here.
format(value: number) => string—
loadingbooleanThe data is on its way.
rowNamestringWhat the first column of the table is called.
tableVisiblebooleanAlso shows the table. For the screen reader it is always there.

It also accepts the attributes of the element it renders: className, style, data-*, aria-* and its events.

CSS variables

These CSS variables are how you adapt it. Declare them on the component's selector, not on :root: the stylesheet redeclares them in the rule itself, and a declaration on the same element always wins.

VariableDefault
--amset-heatmap-cell1.75rem
--amset-heatmap-name4.5rem
--amset-heatmap-tonevar(--amset-accent)

How to change it

.amset-heatmap {
  --amset-heatmap-cell: ...;
  --amset-heatmap-name: ...;
}

In the test bench

Every state and variant, to try one at a time, on its page at storybook.amsetui.com: