Chapter 12 Charts
Treemap
Parts of a whole as areas, in groups: for many parts, where a pie has too few slices. The names are on the tiles where they fit; the tooltip and the table have them all.
import { TreemapChartComponent } 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.0Groups
Up to four groups keep their own colour. Press Tab and use the arrow keys.
Orders by city
- Greater Cairo
- Coast
- Delta
- Upper Egypt
const cities = [
{ city: 'Cairo', region: 'Greater Cairo', orders: 412 },
{ city: 'Alexandria', region: 'Coast', orders: 236 },
];
<ui-treemap-chart
label="Orders by city"
[rows]="cities"
name="city"
value="orders"
group="region"
[height]="320"
/>One group
Without groups, one colour.
Orders by city, plain
<ui-treemap-chart
label="Orders by city, plain"
[rows]="cities"
name="city"
value="orders"
[height]="320"
/>One group against the rest
highlight takes its name.
Orders on the coast
- Greater Cairo
- Coast
- Delta
- Upper Egypt
<ui-treemap-chart
label="Orders on the coast"
[rows]="cities"
name="city"
value="orders"
group="region"
highlight="Coast"
[height]="320"
/>Groups that switch on and off
The names become buttons; the rest fills the room.
Pick the regions
<ui-treemap-chart
label="Pick the regions"
[rows]="cities"
name="city"
value="orders"
group="region"
toggle
[height]="320"
/>Your own formats
Sales by city
- Greater Cairo
- Coast
- Delta
- Upper Egypt
<ui-treemap-chart
label="Sales by city"
[rows]="cities"
name="city"
value="orders"
group="region"
[formatValue]="money"
nameLabel="City"
groupLabel="Region"
valueLabel="Sales"
[height]="320"
/>Open a tile
Click a tile, or press Enter on it, to use its row.
Open a city
- Greater Cairo
- Coast
- Delta
- Upper Egypt
Nothing picked yet.
<ui-treemap-chart
label="Open a city"
[rows]="cities"
name="city"
value="orders"
group="region"
(rowSelect)="open($event)"
/>Loading
Keeps its place while the rows arrive.
Loading
Loading
<ui-treemap-chart
label="Loading"
[rows]="none"
name="city"
value="orders"
loading
[height]="160"
/>Nothing yet
Says so in words.
Nothing yet
Nothing to show yet
<ui-treemap-chart
label="Nothing yet"
[rows]="none"
name="city"
value="orders"
emptyMessage="Nothing to show yet"
[height]="160"
/>In Arabic
الطلبات حسب المدينة
- القاهرة الكبرى
- الساحل
- الدلتا
- الصعيد
<ui-treemap-chart
dir="rtl"
label="الطلبات حسب المدينة"
[rows]="citiesArabic"
name="city"
value="orders"
group="region"
locale="ar-EG"
[height]="320"
/>When to use something else
Inputs
| Name | Type | Default | What it does |
|---|---|---|---|
label | string | — | Required. Names the chart, above it and for screen readers. |
rows | object[] | — | Required. The data. |
name | string | — | Required. The row field with the name of a part. |
value | string | — | Required. The row field with its number. |
group | string | — | The row field with its group. |
highlight | string | — | The group to bring forward; the others turn grey. |
formatValue | (value: number) => string | — | Writes a number. |
nameLabel | string | — | Names the column of names. |
groupLabel | string | — | Names the column of groups. |
valueLabel | string | — | Names the column of numbers. Defaults to Value. |
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. |
toggle | boolean | false | The names become buttons that switch parts on and off. |
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.
- Names are on the tiles at full contrast, over a soft tint of the group colour.