Demo
Heat map with step legend
Documented in HeatMap.
Heat map with step legend
A HeatMap of load by weekday and hour with cell labels, a step color scale of data colors, a toggling list legend, multiple selection and hour groups.
Heat map, 6 rows by 7 columns, values from 0 to 22.
| Hour | Column | Value |
|---|---|---|
| 00 | Mon | 0 |
| 00 | Tue | 5 |
| 00 | Wed | 10 |
| 00 | Thu | 15 |
| 00 | Fri | 3 |
| 00 | Sat | 8 |
| 00 | Sun | 13 |
| 04 | Mon | 11 |
| 04 | Tue | 16 |
| 04 | Wed | 4 |
| 04 | Thu | 9 |
| 04 | Fri | 14 |
| 04 | Sat | 2 |
| 04 | Sun | 7 |
| 08 | Mon | 11 |
| 08 | Tue | 16 |
| 08 | Wed | 21 |
| 08 | Thu | 9 |
| 08 | Fri | 14 |
| 08 | Sat | 13 |
| 08 | Sun | 1 |
| 12 | Mon | 22 |
| 12 | Tue | 10 |
| 12 | Wed | 15 |
| 12 | Thu | 20 |
| 12 | Fri | 8 |
| 12 | Sat | 7 |
| 12 | Sun | 12 |
| 16 | Mon | 16 |
| 16 | Tue | 21 |
| 16 | Wed | 9 |
| 16 | Thu | 14 |
| 16 | Fri | 19 |
| 16 | Sat | 1 |
| 16 | Sun | 6 |
| 20 | Mon | 4 |
| 20 | Tue | 9 |
| 20 | Wed | 14 |
| 20 | Thu | 2 |
| 20 | Fri | 7 |
| 20 | Sat | 12 |
| 20 | Sun | 0 |
Selected: none
Demo.tsx
'use client';
import { useState } from 'react';
import { HeatMap, type HeatMapCellRef } from '@salmonui/charts/heat-map';
const days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
const hours = ['00', '04', '08', '12', '16', '20'];
const load = hours.map((_, y) => days.map((_, x) => ((x * 5 + y * 11) % 17) + (x < 5 && y > 1 && y < 5 ? 6 : 0)));
export default function HeatMapBasicDemo() {
const [selected, setSelected] = useState<readonly HeatMapCellRef[]>([]);
return (
<div className="demo-stack">
<HeatMap
title="Load by weekday and hour"
data={load}
height={360}
xAxis={{ labels: days, labelGroups: [{ from: 0, to: 4, text: 'Weekdays' }, { from: 5, to: 6, text: 'Weekend' }] }}
yAxis={{ labels: hours, title: 'Hour' }}
cells={{ labels: true }}
colorScale={{ kind: 'steps', stops: [{ value: 0, color: '#4c87e4', label: 'Low' }, { value: 8, color: '#4278d8', label: 'Medium' }, { value: 16, color: '#2e59c2', label: 'High' }] }}
selection={{ multiple: true }}
selectedCells={selected}
onSelectedCellsChange={setSelected}
/>
<p className="demo-status" aria-live="polite">
Selected: <code>{selected.map((c) => `${days[c.x]} ${hours[c.y]}`).join(', ') || 'none'}</code>
</p>
</div>
);
}
Toggle a legend step to hide its cells. Tab to the heat map and use the arrow keys, Home / End and PageUp / PageDown; Enter selects the focused cell.