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.
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.
pnpm add @tanstack/charts@1.5.0Bars and a line
The line has a rim, so it reads where it crosses a bar.
Orders and the target
- Orders
- Target
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
<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
<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
<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
<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
<ui-combo-chart
label="Orders, target and phone"
[rows]="months"
x="month"
[series]="lines"
/>A level too
Orders, with a level
- Orders
- Target
<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
<ui-combo-chart
label="Orders, pick the parts"
[rows]="months"
x="month"
[series]="mix"
stacked
toggle
/>Named axes
Orders, with named axes
- Orders
- Target
<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.
<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
<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
<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.
الطلبات والهدف
- الطلبات
- الهدف
<ui-combo-chart
dir="rtl"
label="الطلبات والهدف"
[rows]="monthsArabic"
x="month"
[series]="planArabic"
locale="ar-EG"
/>When to use something else
| If you need | Use |
|---|---|
| Only amounts to compare | Bar chart |
| Only change over time | Line 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. |
x | string | — | Required. The row field along the bottom. |
series | ComboSeries[] | — | Required. The values: key, label, as ('bar' or 'line'), and optionally color. |
stacked | boolean | false | The bars on top of each other. |
curve | 'straight' | 'smooth' | 'step' | 'straight' | How the line joins its values. |
references | ChartReference[] | [] | Levels to compare with: value and label. |
xLabel | string | — | Names the axis of places, and the first table column. |
yLabel | string | — | Names the axis of values. |
yMin | number | — | Where the values start. Defaults to zero or lower. |
yMax | number | — | 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. |
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. |
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.
- Bars and lines differ by their form; bars by texture and lines by dash as well as colour.