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

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.

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

Terminal
pnpm add @tanstack/charts@1.5.0

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

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

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

Angular
<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
Angular
<ui-waterfall-chart
  dir="rtl"
  label="من المبيعات إلى الربح"
  [rows]="yearArabic"
  name="step"
  value="amount"
  total="total"
  locale="ar-EG"
/>

When to use something else

If you needUse
Amounts that do not add upBar chart
How a total changes over timeArea chart
Exact values to read and sortData table

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 step's name.
valuestring — Required. The row field with how much it adds or takes away.
totalstring — The row field that is true where the bar is the total so far.
valueLabelsbooleantrueWrites each change on its bar.
xLabelstring — Names the axis of steps, and the first table column.
yLabelstring — Names the axis of values.
formatValue(value: number) => string — Writes a number.
descriptionstring — A line of text under the name.
hideLabelbooleanfalseKeeps the name for screen readers only.
heightnumber280In pixels. The width follows the box around it.
legendboolean — Shows the names and their colours.
tablebooleantrueThe button that shows the numbers as a table.
patternsbooleantrueTextures over the colours, so shapes differ without colour.
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.
  • A sign and a texture tell a decrease from an increase, as well as the colour.