Chapter 12 Charts
Heatmap
Where a number is high or low across two lists, such as days and hours. Five steps of one colour, light to dark, with the number in each cell where there is room. One button shows it as a table.
import { HeatmapChartComponent } from '@okaapi-ui/angular/charts';Add charts to your app
Charts have their own import, so apps without charts download nothing. They draw with TanStack Charts, installed next to the kit.
pnpm add @tanstack/charts@1.5.0Days and hours
The number is in each cell, so the colour only repeats it. Press Tab and use the arrow keys.
- 9 – 16
- 16 – 22
- 22 – 28
- 28 – 34
- 34+
const week = [
{ day: 'Sat', hour: '9:00', orders: 12 },
{ day: 'Sat', hour: '11:00', orders: 18 },
];
<ui-heatmap-chart
label="Orders by day and hour"
[rows]="week"
x="hour"
y="day"
value="orders"
/>Without numbers
Defaults to off above 60 cells. The legend gives the range of each step.
- 9 – 16
- 16 – 22
- 22 – 28
- 28 – 34
- 34+
<ui-heatmap-chart
label="Orders by day and hour, colour only"
[rows]="week"
x="hour"
y="day"
value="orders"
[valueLabels]="false"
/>Half a year
One cell a day, one column a week.
- 0 – 8
- 8 – 15
- 15 – 22
- 22 – 29
- 29+
<ui-heatmap-chart
label="Orders each day, half a year"
[rows]="year"
x="week"
y="day"
value="orders"
[height]="240"
[formatX]="everyFourth"
/>Branches and months
Your own words for the number.
- 0% – 18%
- 18% – 36%
- 36% – 54%
- 54% – 72%
- 72%+
<ui-heatmap-chart
label="Share of target by branch"
[rows]="branches"
x="month"
y="branch"
value="share"
[formatValue]="percent"
[height]="240"
/>Your own steps
Where each step starts, when the limits mean something.
- 0 – 10
- 10 – 20
- 20 – 30
- 30+
<ui-heatmap-chart
label="Orders, by limits"
[rows]="week"
x="hour"
y="day"
value="orders"
[steps]="steps"
/>Missing cells
An empty cell is missing, never zero.
- 9 – 16
- 16 – 22
- 22 – 28
- 28 – 34
- 34+
<ui-heatmap-chart
label="Orders, with missing hours"
[rows]="gaps"
x="hour"
y="day"
value="orders"
/>Named axes
- 9 – 16
- 16 – 22
- 22 – 28
- 28 – 34
- 34+
<ui-heatmap-chart
label="Orders, with named axes"
[rows]="week"
x="hour"
y="day"
value="orders"
xLabel="Hour"
yLabel="Day"
[height]="340"
/>Open a cell
Click a cell, or press Enter on it, to use its row.
- 9 – 16
- 16 – 22
- 22 – 28
- 28 – 34
- 34+
Nothing picked yet.
<ui-heatmap-chart
label="Orders, open an hour"
[rows]="week"
x="hour"
y="day"
value="orders"
(rowSelect)="open($event)"
/>Loading
Keeps its place while the rows arrive.
Loading
<ui-heatmap-chart
label="Orders, loading"
[rows]="none"
x="hour"
y="day"
value="orders"
loading
[height]="160"
/>Nothing yet
Says so in words.
No orders yet
<ui-heatmap-chart
label="Orders, none yet"
[rows]="none"
x="hour"
y="day"
value="orders"
emptyMessage="No orders yet"
[height]="160"
/>In Arabic
The first hour is on the right.
- ٩ – ١٥
- ١٥ – ٢٠
- ٢٠ – ٢٥
- ٢٥ – ٣٠
- ٣٠+
<ui-heatmap-chart
dir="rtl"
label="الطلبات حسب اليوم والساعة"
[rows]="weekArabic"
x="hour"
y="day"
value="orders"
locale="ar-EG"
/>When to use something else
| If you need | Use |
|---|---|
| Exact values to read and sort | Data table |
| One list of amounts | Bar chart |
| A day to choose | Calendar |
Inputs
| Name | Type | Default | What it does |
|---|---|---|---|
label | string | — | Required. Names the chart, above it and for screen readers. |
rows | object[] | — | Required. The data. |
x | string | — | Required. The row field with the column of a cell. |
y | string | — | Required. The row field with its line. |
value | string | — | Required. The row field with its number. |
valueLabels | boolean | — | Writes the number in each cell. Defaults to on for up to 60 cells. |
steps | number[] | — | Where each step starts, up to five. Defaults to five equal steps. |
xOrder | string[] | — | The order of the columns. Defaults to the order they come in. |
yOrder | string[] | — | The order of the lines. |
xLabel | string | — | Names the bottom axis. |
yLabel | string | — | Names the side axis. |
formatX | (x: string) => string | — | Writes a column. |
formatY | (y: string) => string | — | Writes a line. |
formatValue | (value: number) => string | — | Writes a number. |
description | string | — | A line of text under the name. |
hideLabel | boolean | false | Keeps the name for screen readers only. |
height | number | 280 | In pixels. The width follows the box around it. |
legend | boolean | — | Shows the names and their colours. |
table | boolean | true | The button that shows the numbers as a table. |
loading | boolean | false | Shows that the rows are on their way. |
emptyMessage | string | — | The words when there is nothing to draw. |
locale | string | — | For numbers and dates. Defaults to the language of the page. |
dir | 'ltr' | 'rtl' | — | Defaults to the direction of the page around it. |
[(hidden)] | string[] | [] | Keys of the parts that are off. |
(rowSelect) | row | — | The row under a click, Enter or Space. |
Keyboard and screen readers
| Keys | What they do |
|---|---|
| Tab | Reach the chart, then its next control. |
| Arrow keys | Move to the next or previous value. |
| Home or End | Go to the first or last value. |
| Enter or Space | Pin the value, and open its row if the page uses it. |
| Escape | Unpin the value. |
- A named graphic. Each value is announced as you reach it.
- The same numbers are always there as a real table.
- The number is written in the cell at 7:1 on its colour, or in the table.