Chapter 12 Charts
Area chart
How much, over time: one amount, or parts that add up to a whole. Stacked parts have a texture as well as a colour, and one button shows the same numbers as a table.
import { AreaChartComponent } 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.0One area
From zero up, so the height is the amount.
const months = [
{ month: 'Jan', orders: 42 },
{ month: 'Feb', orders: 58 },
{ month: 'Mar', orders: 76 },
];
const orders = [{ key: 'orders', label: 'Orders' }];
<ui-area-chart
label="Orders by month"
[rows]="months"
x="month"
[series]="orders"
/>Smooth
A soft curve that never rises above or dips below the real values.
<ui-area-chart
label="Orders, smooth"
[rows]="months"
x="month"
[series]="orders"
curve="smooth"
/>Steps
For an amount that holds until it changes, such as stock.
<ui-area-chart
label="Items in stock"
[rows]="stock"
x="month"
[series]="items"
curve="step"
/>Two that overlap
Edges differ by dash. Two at most: more hide each other.
- Web
- Branch
<ui-area-chart
label="Web and branch"
[rows]="months"
x="month"
[series]="two"
/>Stacked
Parts that add up to a total.
- Web
- Branch
- Phone
const channels = [
{ key: 'web', label: 'Web' },
{ key: 'branch', label: 'Branch' },
{ key: 'phone', label: 'Phone' },
];
<ui-area-chart
label="Orders by channel, stacked"
[rows]="months"
x="month"
[series]="channels"
layout="stacked"
/>Stacked and smooth
- Web
- Branch
- Phone
<ui-area-chart
label="Orders by channel, smooth"
[rows]="months"
x="month"
[series]="channels"
layout="stacked"
curve="smooth"
/>Shares of a whole
How the mix changes. The tooltip gives the number and the share.
- Web
- Branch
- Phone
<ui-area-chart
label="Share of orders by channel"
[rows]="months"
x="month"
[series]="channels"
layout="percent"
/>Dates
Spaced by real time.
<ui-area-chart
label="Visits by day"
[rows]="days"
x="date"
[series]="visits"
curve="smooth"
/>Missing values
A missing value is a gap, never a zero.
<ui-area-chart
label="Orders, one month missing"
[rows]="gaps"
x="month"
[series]="orders"
/>A target
A level to reach, named on the chart.
const target = [{ value: 80, label: 'Target 80' }];
<ui-area-chart
label="Orders against the target"
[rows]="months"
x="month"
[series]="orders"
[references]="target"
/>One area against the rest
highlight takes the key of the series.
- Web
- Branch
- Phone
<ui-area-chart
label="Orders by channel, web"
[rows]="months"
x="month"
[series]="channels"
layout="stacked"
highlight="web"
/>Parts that switch on and off
The names become buttons.
<ui-area-chart
label="Orders, pick the channels"
[rows]="months"
x="month"
[series]="channels"
layout="stacked"
toggle
/>Named axes
<ui-area-chart
label="Orders, with named axes"
[rows]="months"
x="month"
[series]="orders"
xLabel="Month"
yLabel="Orders"
[yMax]="120"
/>Without textures
Only where something else tells the parts apart.
- Web
- Branch
- Phone
<ui-area-chart
label="Orders by channel, plain"
[rows]="months"
x="month"
[series]="channels"
layout="stacked"
[patterns]="false"
/>Loading
Keeps its place while the rows arrive.
Loading
<ui-area-chart
label="Orders, loading"
[rows]="none"
x="month"
[series]="orders"
loading
[height]="160"
/>Nothing yet
Says so in words.
No orders yet
<ui-area-chart
label="Orders, none yet"
[rows]="none"
x="month"
[series]="orders"
emptyMessage="No orders yet"
[height]="160"
/>In Arabic
Time runs from right to left.
- الموقع
- الفرع
- الهاتف
<ui-area-chart
dir="rtl"
label="الطلبات حسب القناة"
[rows]="monthsArabic"
x="month"
[series]="channelsArabic"
locale="ar-EG"
layout="stacked"
/>When to use something else
| If you need | Use |
|---|---|
| Several values to compare over time | Line chart |
| Amounts of separate things | Bar chart |
| Parts of one whole, at one moment | Pie 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 with the place: text, a number or a Date (read in UTC). |
series | ChartSeries[] | — | Required. The values: key, label, and optionally color (1 to 4 or muted). |
layout | 'overlap' | 'stacked' | 'percent' | 'overlap' | Over each other, on top of each other, or as shares of a whole. |
curve | 'straight' | 'smooth' | 'step' | 'straight' | How values are joined. |
highlight | string | — | What to bring forward; the rest turns grey. |
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.
- Stacked parts differ by texture as well as colour; overlapping ones by the dash of their edge.