Chapter 12 Charts
Line chart
How values change over time or along a scale. Every line differs by dash as well as colour, the arrow keys walk the values, and one button shows the same numbers as a table. Time runs from right to left in Arabic.
import { LineChartComponent } 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 line
Rows, the field along the bottom, and the lines. Point at it, or press Tab and use the arrow keys.
const months = [
{ month: 'Jan', orders: 42 },
{ month: 'Feb', orders: 58 },
{ month: 'Mar', orders: 76 },
];
const orders = [{ key: 'orders', label: 'Orders' }];
<ui-line-chart
label="Orders by month"
[rows]="months"
x="month"
[series]="orders"
/>Several lines
Each line has its own colour and its own dash, so the colour is never the only difference.
- Web
- Branch
- Phone
const channels = [
{ key: 'web', label: 'Web' },
{ key: 'branch', label: 'Branch' },
{ key: 'phone', label: 'Phone' },
];
<ui-line-chart
label="Orders by channel"
[rows]="months"
x="month"
[series]="channels"
yLabel="Orders"
/>Names at the line ends
Nothing to look up in a legend. Names that would touch move apart.
<ui-line-chart
label="Orders by channel, named"
[rows]="months"
x="month"
[series]="channels"
endLabels
/>Smooth
A soft curve that never rises above or dips below the real values.
<ui-line-chart
label="Orders, smooth"
[rows]="months"
x="month"
[series]="orders"
curve="smooth"
/>Steps
For a value that holds until it changes, such as a price or a stock level.
<ui-line-chart
label="Price of one item"
[rows]="prices"
x="day"
[series]="price"
curve="step"
/>Filled
A soft fill under one line, from zero up.
const filled = [{ key: 'orders', label: 'Orders', area: true }];
<ui-line-chart
label="Orders, filled"
[rows]="months"
x="month"
[series]="filled"
curve="smooth"
/>Without dots
Up to 12 rows get a dot on each value. Turn it on or off yourself.
<ui-line-chart
label="Orders, no dots"
[rows]="months"
x="month"
[series]="orders"
[points]="false"
/>Dates
Dates are spaced by real time and written in the reader's language. The bottom shows months or days, whichever fits.
const days = [{ date: new Date('2026-06-01'), visits: 210 }];
const visits = [{ key: 'visits', label: 'Visits' }];
<ui-line-chart
label="Visits by day"
[rows]="days"
x="date"
[series]="visits"
/>Numbers along the bottom
Any scale, not only time: here, distance.
const climb = [{ km: 0, height: 120 }, { km: 2.5, height: 180 }];
<ui-line-chart
label="Height along the road"
[rows]="climb"
x="km"
[series]="height"
xLabel="Distance (km)"
yLabel="Height (m)"
curve="smooth"
/>Missing values
A missing value is a gap, never a zero.
const gaps = [{ month: 'Jan', orders: 42 }, { month: 'Feb', orders: null }];
<ui-line-chart
label="Orders with two months missing"
[rows]="gaps"
x="month"
[series]="orders"
/>Missing values, joined
When the gap means nothing, join across it.
<ui-line-chart
label="Orders, joined across the gap"
[rows]="gaps"
x="month"
[series]="orders"
connectGaps
/>One line against the rest
Bring one line forward; the others turn grey behind it. The way to show more than four lines.
<ui-line-chart
label="Orders by branch"
[rows]="branches"
x="month"
[series]="branchSeries"
highlight="b3"
endLabels
[points]="false"
/>Lines that switch on and off
The names become buttons. A switched-off name is crossed out, and screen readers hear whether it is pressed.
<ui-line-chart
label="Orders, pick the channels"
[rows]="months"
x="month"
[series]="channels"
toggle
/>A target
A level to reach, named on the chart.
const target = [{ value: 80, label: 'Target 80' }];
<ui-line-chart
label="Orders against the target"
[rows]="months"
x="month"
[series]="orders"
[references]="target"
/>A normal range
Where values should stay. Readers see at once when the line leaves it.
const normal = [{ from: 50, to: 80, label: 'Normal, 50 to 80' }];
<ui-line-chart
label="Orders inside the normal range"
[rows]="months"
x="month"
[series]="orders"
[bands]="normal"
/>Events
Mark what happened, so a jump explains itself.
const changes = [{ x: 'Mar', label: 'New site' }];
<ui-line-chart
label="Orders and what changed"
[rows]="months"
x="month"
[series]="orders"
[events]="changes"
/>Highest and lowest
The two values people ask about first, written on the chart.
<ui-line-chart
label="Orders, highest and lowest"
[rows]="months"
x="month"
[series]="orders"
extremes
[yMin]="0"
[yMax]="120"
/>A range around a line
How sure the number is: a low and a high field in each row. The table shows the range too.
const likely = { low: 'low', high: 'high', label: 'Likely range' };
<ui-line-chart
label="Orders, with the likely range"
[rows]="months"
x="month"
[series]="orders"
[range]="likely"
curve="smooth"
/>A forecast
Dotted, with hollow dots, from the last real month on.
<ui-line-chart
label="Orders and the forecast"
[rows]="forecast"
x="month"
[series]="orders"
forecastFrom="Jun"
/>Below zero
The zero line is a reference like any other.
const zero = [{ value: 0, label: 'Zero' }];
<ui-line-chart
label="Profit by month"
[rows]="profit"
x="month"
[series]="profitSeries"
[references]="zero"
[formatY]="thousands"
/>Your own formats
Money, percent or units, the same in the axis, the tooltip and the table. Set where the axis starts and ends.
const percent = (y) => new Intl.NumberFormat('en', { style: 'percent' }).format(y);
<ui-line-chart
label="Share of orders from the site"
[rows]="share"
x="month"
[series]="shareSeries"
[formatY]="percent"
[yMin]="0"
[yMax]="1"
/>A different period
New rows redraw the chart in place.
<ui-line-chart
label="Visits"
[rows]="shown"
x="date"
[series]="visits"
[points]="false"
/>New values
Add to the rows and the line moves on. Replace the array, do not change it.
<ui-line-chart
label="Temperature"
[rows]="readings"
x="n"
[series]="reading"
[yMin]="15"
[yMax]="30"
[formatY]="degrees"
/>Open a value
Click a value, or press Enter on it, to use its row.
Nothing picked yet.
<ui-line-chart
label="Orders, open a month"
[rows]="months"
x="month"
[series]="orders"
(rowSelect)="open($event)"
/>Sparklines
A small line for a card or a table cell. No axes, so put the number beside it.
Orders
Branch
<ui-line-chart
sparkline
label="Orders, last six months"
[rows]="months"
x="month"
[series]="orders"
[height]="48"
curve="smooth"
/>Small charts side by side
The same scale in each, so they compare. Better than many lines in one chart.
<ui-line-chart
label="Web"
[rows]="months"
x="month"
[series]="web"
[yMin]="0"
[yMax]="100"
[height]="180"
[points]="false"
/>A thousand values
Long data stays one clear line; the arrow keys still reach every value.
<ui-line-chart
label="A thousand readings"
[rows]="long"
x="n"
[series]="reading"
[points]="false"
/>Loading
Keeps its place while the rows arrive.
Loading
<ui-line-chart
label="Orders, loading"
[rows]="none"
x="month"
[series]="orders"
loading
[height]="160"
/>Nothing yet
Says so in words.
No orders yet
<ui-line-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, the axis moves to the right, and numbers are in Arabic digits.
- الموقع
- الفرع
- الهاتف
<ui-line-chart dir="rtl"
label="الطلبات كل شهر"
[rows]="monthsArabic"
x="month"
[series]="channelsArabic"
locale="ar-EG"
[references]="targetArabic"
/>In Arabic, names at the line ends
<ui-line-chart dir="rtl"
label="الطلبات حسب القناة"
[rows]="monthsArabic"
x="month"
[series]="channelsArabic"
locale="ar-EG"
endLabels
curve="smooth"
/>When to use something else
| If you need | Use |
|---|---|
| One number and how it changed | Stat |
| Exact values to read and sort | Data table |
| A level inside a known range | Meter |
| What happened, in order, in words | Timeline |
Inputs
| Name | Type | Default | What it does |
|---|---|---|---|
label | string | — | Required. Names the chart, above it and for screen readers. |
rows | object[] | — | Required. One row per place along the bottom. |
x | string | — | Required. The row field along the bottom: text, a number or a Date (read in UTC). |
series | LineSeries[] | — | Required. The lines: key, label, and optionally color (1 to 4 or muted), dash and area. |
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. |
curve | 'straight' | 'smooth' | 'step' | 'straight' | How values are joined. |
points | boolean | — | A dot on every value. Defaults to on for up to 12 rows. |
connectGaps | boolean | false | Joins across missing values. |
highlight | string | — | The key of the line to bring forward; the others turn grey. |
toggle | boolean | false | The names become buttons that switch lines on and off. |
legend | boolean | — | Defaults to on for two lines or more, unless the names are at the line ends. |
endLabels | boolean | false | Writes each name at the end of its line. |
extremes | boolean | false | Marks the highest and the lowest value. |
references | ChartReference[] | [] | Levels to compare with: value and label. |
bands | ChartBand[] | [] | Normal ranges: from, to and label. |
events | ChartEvent[] | [] | What happened and where: x and label. |
range | ChartRange | — | The range around the first line: low and high fields, and a label. |
forecastFrom | string | number | Date | — | The last real place; after it the lines are dotted. |
xLabel | string | — | Names the bottom axis, and the first table column. |
yLabel | string | — | Names the side axis. |
yMin | number | — | Where the side axis starts. Defaults to fit the values. |
yMax | number | — | Where the side axis ends. |
formatX | (x) => string | — | Writes a place along the bottom. |
formatY | (y: number) => string | — | Writes a value, in the axis, the tooltip and the table. |
sparkline | boolean | false | A small line with no axes. |
table | boolean | true | The button that shows the numbers as a table. |
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 lines 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.
- Lines differ by dash as well as colour, and text is never drawn in a line colour.