Heatmap
Values on a grid of two categories, as shades of one colour: requests by weekday and hour. Darker is more; the scale gives the range.
import { Heatmap } from '@sypnia/ui/react'
Requests by weekday and hour
Requests
Per hour, last week
Day000102030405060708091011121314151617181920212223
Mon
Tue
Wed
Thu
Fri
Sat
Sun
View as table
| Day | 00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Mon | 15 | 22 | 29 | 36 | 18 | 25 | 32 | 39 | 188 | 129 | 160 | 191 | 132 | 163 | 194 | 135 | 166 | 197 | 138 | 169 | 30 | 37 | 19 | 26 |
| Tue | 16 | 23 | 30 | 37 | 19 | 26 | 33 | 15 | 205 | 146 | 177 | 208 | 149 | 180 | 121 | 152 | 183 | 124 | 155 | 186 | 31 | 38 | 20 | 27 |
| Wed | 17 | 24 | 31 | 38 | 20 | 27 | 34 | 16 | 132 | 163 | 194 | 135 | 166 | 197 | 138 | 169 | 200 | 141 | 172 | 203 | 32 | 39 | 21 | 28 |
| Thu | 18 | 25 | 32 | 39 | 21 | 28 | 35 | 17 | 149 | 180 | 121 | 152 | 183 | 124 | 155 | 186 | 127 | 158 | 189 | 130 | 33 | 15 | 22 | 29 |
| Fri | 19 | 26 | 33 | 15 | 22 | 29 | 36 | 18 | 166 | 197 | 138 | 169 | 200 | 141 | 172 | 203 | 144 | 175 | 206 | 147 | 34 | 16 | 23 | 30 |
| Sat | 8 | 11 | 14 | 6 | 9 | 12 | 15 | 8 | 73 | 50 | 62 | 74 | 51 | 63 | 76 | 52 | 64 | 77 | 53 | 66 | 14 | 7 | 10 | 12 |
| Sun | — | — | — | — | 10 | 12 | 15 | 8 | 80 | 56 | 69 | 81 | 58 | 70 | 82 | 59 | 71 | 84 | 60 | 72 | 14 | 7 | 10 | 13 |
Code
import { Heatmap } from '@sypnia/ui/react';
// Requests by weekday and hour. Darker is more; hover or focus a cell to read it.
const days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
const hours = Array.from({ length: 24 }, (_, h) => String(h).padStart(2, '0'));
const values = days.map((_, d) => hours.map((_, h) => (d === 6 && h < 4 ? null : Math.round((d < 5 ? 1 : 0.4) * (h >= 8 && h <= 19 ? 120 + ((h * 31 + d * 17) % 90) : 15 + ((h * 7 + d) % 25))))));
export default function Week() {
return <Heatmap title="Requests" subtitle="Per hour, last week" rows={days} columns={hours} values={values} rowLabel="Day" />;
} When to use it
Use it when
- Patterns by day and hour, or any two categories.
Do not use it when
- Exact comparisons: shades are read roughly; use the table or a bar chart.
For everyone
- It is a grid: each cell is focusable and named with its row, column and value.
- Cells without a measure are outlined, not shaded.
Props
| Heatmap | Type | Default |
|---|---|---|
columnsrequired | string[] | |
rowsrequired | string[] | |
titlerequired | ReactNode | |
valuesrequiredvalues[row][column]; null when there is no measure. | (number | null)[][] | |
empty | ReactNode | |
error | ReactNode | |
formatValue | Fmt | |
height | number | |
loading | boolean | |
rowLabel | string | |
subtitle | ReactNode |