Chapter 12 Charts
Waterfall chart
How a total is reached, step by step, up and down. Every bar starts where the one before ended, and says its change with a sign. Decreases have a texture as well as a colour.
import { WaterfallChartComponent } 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.0Steps and totals
A row with total true shows the sum so far. Press Tab and use the arrow keys.
From sales to profit
- Increase
- Decrease
- Total
const year = [
{ step: 'Sales', amount: 820 },
{ step: 'Costs', amount: -410 },
{ step: 'Profit', total: true },
];
<ui-waterfall-chart
label="From sales to profit"
[rows]="year"
name="step"
value="amount"
total="total"
/>Below zero
Bars cross the zero line.
Cash in a month
- Increase
- Decrease
- Total
<ui-waterfall-chart
label="Cash in a month"
[rows]="cash"
name="step"
value="amount"
total="total"
/>Your own formats
In the labels, the axis, the tooltip and the table.
From sales to profit, in thousands
- Increase
- Decrease
- Total
<ui-waterfall-chart
label="From sales to profit, in thousands"
[rows]="year"
name="step"
value="amount"
total="total"
[formatValue]="thousands"
/>Without values
The tooltip and the table still have them.
From sales to profit, plain
- Increase
- Decrease
- Total
<ui-waterfall-chart
label="From sales to profit, plain"
[rows]="year"
name="step"
value="amount"
total="total"
[valueLabels]="false"
/>Named axes
From sales to profit, named
- Increase
- Decrease
- Total
<ui-waterfall-chart
label="From sales to profit, named"
[rows]="year"
name="step"
value="amount"
total="total"
xLabel="Step"
yLabel="Thousand pounds"
/>Without textures
The signs on the bars still tell them apart.
From sales to profit, no textures
- Increase
- Decrease
- Total
<ui-waterfall-chart
label="From sales to profit, no textures"
[rows]="year"
name="step"
value="amount"
total="total"
[patterns]="false"
/>Open a step
Click a bar, or press Enter on it, to use its row.
Open a step
- Increase
- Decrease
- Total
Nothing picked yet.
<ui-waterfall-chart
label="Open a step"
[rows]="year"
name="step"
value="amount"
total="total"
(rowSelect)="open($event)"
/>Loading
Keeps its place while the rows arrive.
Loading
Loading
<ui-waterfall-chart
label="Loading"
[rows]="none"
name="step"
value="amount"
total="total"
loading
[height]="160"
/>Nothing yet
Says so in words.
Nothing yet
Nothing to show yet
<ui-waterfall-chart
label="Nothing yet"
[rows]="none"
name="step"
value="amount"
total="total"
emptyMessage="Nothing to show yet"
[height]="160"
/>In Arabic
The first step is on the right.
من المبيعات إلى الربح
- Increase
- Decrease
- Total
<ui-waterfall-chart
dir="rtl"
label="من المبيعات إلى الربح"
[rows]="yearArabic"
name="step"
value="amount"
total="total"
locale="ar-EG"
/>When to use something else
| If you need | Use |
|---|---|
| Amounts that do not add up | Bar chart |
| How a total changes over time | Area chart |
| Exact values to read and sort | Data table |
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 step's name. |
value | string | — | Required. The row field with how much it adds or takes away. |
total | string | — | The row field that is true where the bar is the total so far. |
valueLabels | boolean | true | Writes each change on its bar. |
xLabel | string | — | Names the axis of steps, and the first table column. |
yLabel | string | — | Names the axis of values. |
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. |
patterns | boolean | true | Textures over the colours, so shapes differ without colour. |
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.
- A sign and a texture tell a decrease from an increase, as well as the colour.