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

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.

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

Terminal
pnpm add @tanstack/charts@1.5.0

One line

Rows, the field along the bottom, and the lines. Point at it, or press Tab and use the arrow keys.

Orders by month
Angular
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.

Orders by channel
  • Web
  • Branch
  • Phone
Angular
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.

Orders by channel, named
Angular
<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.

Orders, smooth
Angular
<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.

Price of one item
Angular
<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.

Orders, filled
Angular
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.

Orders, no dots
Angular
<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.

Visits by day
Angular
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.

Height along the road
Angular
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.

Orders with two months missing
Angular
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.

Orders, joined across the gap
Angular
<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.

Orders by branch
Angular
<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.

Orders, pick the channels
Angular
<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.

Orders against the target
Angular
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.

Orders inside the normal range
Angular
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.

Orders and what changed
Angular
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.

Orders, highest and lowest
Angular
<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.

Orders, with the likely range
Angular
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.

Orders and the forecast
Angular
<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.

Profit by month
Angular
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.

Share of orders from the site
Angular
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.

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

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

Orders, open a month

Nothing picked yet.

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

96

Branch

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

Web
Branch
Phone
Angular
<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.

A thousand readings
Angular
<ui-line-chart
  label="A thousand readings"
  [rows]="long"
  x="n"
  [series]="reading"
  [points]="false"
/>

Loading

Keeps its place while the rows arrive.

Orders, loading

Loading

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

Nothing yet

Says so in words.

Orders, none yet

No orders yet

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

الطلبات كل شهر
  • الموقع
  • الفرع
  • الهاتف
Angular
<ui-line-chart dir="rtl"
  label="الطلبات كل شهر"
  [rows]="monthsArabic"
  x="month"
  [series]="channelsArabic"
  locale="ar-EG"
  [references]="targetArabic"
/>

In Arabic, names at the line ends

الطلبات حسب القناة
Angular
<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 needUse
One number and how it changedStat
Exact values to read and sortData table
A level inside a known rangeMeter
What happened, in order, in wordsTimeline

Inputs

NameTypeDefaultWhat it does
labelstring — Required. Names the chart, above it and for screen readers.
rowsobject[] — Required. One row per place along the bottom.
xstring — Required. The row field along the bottom: text, a number or a Date (read in UTC).
seriesLineSeries[] — Required. The lines: key, label, and optionally color (1 to 4 or muted), dash and area.
descriptionstring — A line of text under the name.
hideLabelbooleanfalseKeeps the name for screen readers only.
heightnumber280In pixels. The width follows the box around it.
curve'straight' | 'smooth' | 'step''straight'How values are joined.
pointsboolean — A dot on every value. Defaults to on for up to 12 rows.
connectGapsbooleanfalseJoins across missing values.
highlightstring — The key of the line to bring forward; the others turn grey.
togglebooleanfalseThe names become buttons that switch lines on and off.
legendboolean — Defaults to on for two lines or more, unless the names are at the line ends.
endLabelsbooleanfalseWrites each name at the end of its line.
extremesbooleanfalseMarks the highest and the lowest value.
referencesChartReference[][]Levels to compare with: value and label.
bandsChartBand[][]Normal ranges: from, to and label.
eventsChartEvent[][]What happened and where: x and label.
rangeChartRange — The range around the first line: low and high fields, and a label.
forecastFromstring | number | Date — The last real place; after it the lines are dotted.
xLabelstring — Names the bottom axis, and the first table column.
yLabelstring — Names the side axis.
yMinnumber — Where the side axis starts. Defaults to fit the values.
yMaxnumber — 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.
sparklinebooleanfalseA small line with no axes.
tablebooleantrueThe button that shows the numbers as a table.
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 lines 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.
  • Lines differ by dash as well as colour, and text is never drawn in a line colour.