Skip to content
Okaapiأوكابي
Framework for the code
Theme
Okaapi on GitHub

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.

Use it in Angular
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.

Terminal
pnpm add @tanstack/charts@1.5.0

Groups

Up to four groups keep their own colour. Press Tab and use the arrow keys.

Orders by city
  • Greater Cairo
  • Coast
  • Delta
  • Upper Egypt
Angular
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
Angular
<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
Angular
<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
Angular
<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
Angular
<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.

Angular
<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

Angular
<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

Angular
<ui-treemap-chart
  label="Nothing yet"
  [rows]="none"
  name="city"
  value="orders"
  emptyMessage="Nothing to show yet"
  [height]="160"
/>

In Arabic

الطلبات حسب المدينة
  • القاهرة الكبرى
  • الساحل
  • الدلتا
  • الصعيد
Angular
<ui-treemap-chart
  dir="rtl"
  label="الطلبات حسب المدينة"
  [rows]="citiesArabic"
  name="city"
  value="orders"
  group="region"
  locale="ar-EG"
  [height]="320"
/>

When to use something else

If you needUse
Up to five partsPie chart
To compare the parts closelyBar chart
Parts inside parts to open and closeTree

Inputs

NameTypeDefaultWhat it does
labelstring — Required. Names the chart, above it and for screen readers.
rowsobject[] — Required. The data.
namestring — Required. The row field with the name of a part.
valuestring — Required. The row field with its number.
groupstring — The row field with its group.
highlightstring — The group to bring forward; the others turn grey.
formatValue(value: number) => string — Writes a number.
nameLabelstring — Names the column of names.
groupLabelstring — Names the column of groups.
valueLabelstring — Names the column of numbers. Defaults to Value.
descriptionstring — A line of text under the name.
hideLabelbooleanfalseKeeps the name for screen readers only.
heightnumber280In pixels. The width follows the box around it.
togglebooleanfalseThe names become buttons that switch parts on and off.
legendboolean — Shows the names and their colours.
tablebooleantrueThe button that shows the numbers as a table.
loadingbooleanfalseShows that the rows are on their way.
emptyMessagestring — The words when there is nothing to draw.
localestring — 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

KeysWhat 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.