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

Chapter 12 Charts

Combo chart

Bars with a line over them, on one scale: what happened beside what it is measured against. One scale only: two would make any two lines look related. One button shows the same numbers as a table.

Use it in Angular
import { ComboChartComponent } 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

Bars and a line

The line has a rim, so it reads where it crosses a bar.

Orders and the target
  • Orders
  • Target
Angular
const months = [
  { month: 'Jan', orders: 42, target: 60 },
  { month: 'Feb', orders: 58, target: 60 },
];
const plan = [
  { key: 'orders', label: 'Orders', as: 'bar' },
  { key: 'target', label: 'Target', as: 'line' },
];

<ui-combo-chart
  label="Orders and the target"
  [rows]="months"
  x="month"
  [series]="plan"
/>

A moving average

The shape under the noise.

Orders and their average
  • Orders
  • Average of three months
Angular
<ui-combo-chart
  label="Orders and their average"
  [rows]="average"
  x="month"
  [series]="trend"
  curve="smooth"
/>

A target in steps

For a level that holds until it changes.

Orders and the target, in steps
  • Orders
  • Target
Angular
<ui-combo-chart
  label="Orders and the target, in steps"
  [rows]="months"
  x="month"
  [series]="plan"
  curve="step"
/>

Bars side by side

Two channels and the target
  • Web
  • Branch
  • Target
Angular
<ui-combo-chart
  label="Two channels and the target"
  [rows]="months"
  x="month"
  [series]="mix"
/>

Bars stacked

The line compares with the total.

Stacked channels and the target
  • Web
  • Branch
  • Target
Angular
<ui-combo-chart
  label="Stacked channels and the target"
  [rows]="months"
  x="month"
  [series]="mix"
  stacked
/>

Two lines

The second is dashed.

Orders, target and phone
  • Orders
  • Target
  • Phone
Angular
<ui-combo-chart
  label="Orders, target and phone"
  [rows]="months"
  x="month"
  [series]="lines"
/>

A level too

Orders, with a level
  • Orders
  • Target
Angular
<ui-combo-chart
  label="Orders, with a level"
  [rows]="months"
  x="month"
  [series]="plan"
  [references]="target"
/>

Parts that switch on and off

The names become buttons.

Orders, pick the parts
Angular
<ui-combo-chart
  label="Orders, pick the parts"
  [rows]="months"
  x="month"
  [series]="mix"
  stacked
  toggle
/>

Named axes

Orders, with named axes
  • Orders
  • Target
Angular
<ui-combo-chart
  label="Orders, with named axes"
  [rows]="months"
  x="month"
  [series]="plan"
  xLabel="Month"
  yLabel="Orders"
  [yMax]="120"
/>

Open a value

Click a bar or a point, or press Enter on it, to use its row.

Orders, open a month
  • Orders
  • Target

Nothing picked yet.

Angular
<ui-combo-chart
  label="Orders, open a month"
  [rows]="months"
  x="month"
  [series]="plan"
  (rowSelect)="open($event)"
/>

Loading

Keeps its place while the rows arrive.

Orders, loading

Loading

Angular
<ui-combo-chart
  label="Orders, loading"
  [rows]="none"
  x="month"
  [series]="plan"
  loading
  [height]="160"
/>

Nothing yet

Says so in words.

Orders, none yet

No orders yet

Angular
<ui-combo-chart
  label="Orders, none yet"
  [rows]="none"
  x="month"
  [series]="plan"
  emptyMessage="No orders yet"
  [height]="160"
/>

In Arabic

Time runs from right to left.

الطلبات والهدف
  • الطلبات
  • الهدف
Angular
<ui-combo-chart
  dir="rtl"
  label="الطلبات والهدف"
  [rows]="monthsArabic"
  x="month"
  [series]="planArabic"
  locale="ar-EG"
/>

When to use something else

If you needUse
Only amounts to compareBar chart
Only change over timeLine 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.
xstring — Required. The row field along the bottom.
seriesComboSeries[] — Required. The values: key, label, as ('bar' or 'line'), and optionally color.
stackedbooleanfalseThe bars on top of each other.
curve'straight' | 'smooth' | 'step''straight'How the line joins its values.
referencesChartReference[][]Levels to compare with: value and label.
xLabelstring — Names the axis of places, and the first table column.
yLabelstring — Names the axis of values.
yMinnumber — Where the values start. Defaults to zero or lower.
yMaxnumber — Where the values end.
formatX(x) => string — Writes a place.
formatY(y: number) => string — Writes a value, in the axis, the tooltip and the table.
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.
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.
  • Bars and lines differ by their form; bars by texture and lines by dash as well as colour.