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

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.

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

Terminal
pnpm add @tanstack/charts@1.5.0

One area

From zero up, so the height is the amount.

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

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

Items in stock
Angular
<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 and branch
  • Web
  • Branch
Angular
<ui-area-chart
  label="Web and branch"
  [rows]="months"
  x="month"
  [series]="two"
/>

Stacked

Parts that add up to a total.

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

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

Share of orders by channel
  • Web
  • Branch
  • Phone
Angular
<ui-area-chart
  label="Share of orders by channel"
  [rows]="months"
  x="month"
  [series]="channels"
  layout="percent"
/>

Dates

Spaced by real time.

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

Orders, one month missing
Angular
<ui-area-chart
  label="Orders, one month missing"
  [rows]="gaps"
  x="month"
  [series]="orders"
/>

A target

A level to reach, named on the chart.

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

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

Orders, pick the channels
Angular
<ui-area-chart
  label="Orders, pick the channels"
  [rows]="months"
  x="month"
  [series]="channels"
  layout="stacked"
  toggle
/>

Named axes

Orders, with named axes
Angular
<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.

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

Orders, loading

Loading

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

الطلبات حسب القناة
  • الموقع
  • الفرع
  • الهاتف
Angular
<ui-area-chart
  dir="rtl"
  label="الطلبات حسب القناة"
  [rows]="monthsArabic"
  x="month"
  [series]="channelsArabic"
  locale="ar-EG"
  layout="stacked"
/>

When to use something else

If you needUse
Several values to compare over timeLine chart
Amounts of separate thingsBar chart
Parts of one whole, at one momentPie 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 with the place: text, a number or a Date (read in UTC).
seriesChartSeries[] — 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.
highlightstring — What to bring forward; the rest turns grey.
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.
  • Stacked parts differ by texture as well as colour; overlapping ones by the dash of their edge.