Chapter 12 Charts
Scatter chart
Two numbers for each thing, to see whether they go together. A third number makes bubbles. Groups differ by shape as well as colour, and one button shows the same numbers as a table.
import { ScatterChartComponent } 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.0Two numbers
Each point is one thing. Press Tab and use the arrow keys to read each one.
const items = [
{ item: 'Tea', price: 20, orders: 96 },
{ item: 'Grill', price: 160, orders: 31 },
];
<ui-scatter-chart
label="Price and orders"
[rows]="items"
x="price"
y="orders"
name="item"
xLabel="Price"
yLabel="Orders"
/>Groups
Circle, ring, hexagon and hollow hexagon: up to four groups.
- Drinks
- Food
- Sweets
- Offers
<ui-scatter-chart
label="Price and orders by kind"
[rows]="items"
x="price"
y="orders"
name="item"
xLabel="Price"
yLabel="Orders"
group="kind"
/>Bubbles
The area of a bubble is the third number.
<ui-scatter-chart
label="Price, orders and profit"
[rows]="items"
x="price"
y="orders"
name="item"
xLabel="Price"
yLabel="Orders"
size="profit"
sizeLabel="Profit"
[height]="340"
/>Bubbles in groups
- Drinks
- Food
- Sweets
- Offers
<ui-scatter-chart
label="Price, orders and profit by kind"
[rows]="items"
x="price"
y="orders"
name="item"
xLabel="Price"
yLabel="Orders"
size="profit"
sizeLabel="Profit"
group="kind"
[height]="340"
/>A trend
The straight line that fits best. It shows that two numbers move together, not why.
<ui-scatter-chart
label="Price and orders, with the trend"
[rows]="items"
x="price"
y="orders"
name="item"
xLabel="Price"
yLabel="Orders"
trend
/>Names on the points
For a few points.
<ui-scatter-chart
label="Offers and drinks, named"
[rows]="items.slice(0, 4)"
x="price"
y="orders"
name="item"
nameLabels
xLabel="Price"
yLabel="Orders"
[yMax]="120"
/>Lines that divide
Named levels cut the chart into parts.
<ui-scatter-chart
label="Price and orders, divided"
[rows]="items"
x="price"
y="orders"
name="item"
xLabel="Price"
yLabel="Orders"
[xReferences]="budget"
[yReferences]="median"
/>One group against the rest
highlight takes the name of the group.
- Drinks
- Food
- Sweets
- Offers
<ui-scatter-chart
label="Price and orders, sweets"
[rows]="items"
x="price"
y="orders"
name="item"
xLabel="Price"
yLabel="Orders"
group="kind"
highlight="Sweets"
/>Groups that switch on and off
The names become buttons.
<ui-scatter-chart
label="Price and orders, pick the kinds"
[rows]="items"
x="price"
y="orders"
name="item"
xLabel="Price"
yLabel="Orders"
group="kind"
toggle
/>Many points
<ui-scatter-chart
label="Size and time of 160 orders"
[rows]="cloud"
x="size"
y="time"
xLabel="Items"
yLabel="Minutes"
trend
/>Your own range
Start both axes where it matters.
<ui-scatter-chart
label="Price and orders, from zero"
[rows]="items"
x="price"
y="orders"
name="item"
xLabel="Price"
yLabel="Orders"
[xMin]="0"
[yMin]="0"
[xMax]="200"
[yMax]="120"
/>Open a point
Click a point, or press Enter on it, to use its row.
Nothing picked yet.
<ui-scatter-chart
label="Price and orders, open one"
[rows]="items"
x="price"
y="orders"
name="item"
xLabel="Price"
yLabel="Orders"
(rowSelect)="open($event)"
/>Loading
Keeps its place while the rows arrive.
Loading
<ui-scatter-chart
label="Orders, loading"
[rows]="none"
x="price"
y="orders"
loading
[height]="160"
/>Nothing yet
Says so in words.
No orders yet
<ui-scatter-chart
label="Orders, none yet"
[rows]="none"
x="price"
y="orders"
emptyMessage="No orders yet"
[height]="160"
/>In Arabic
Low numbers are on the right.
- مشروبات
- طعام
- حلويات
<ui-scatter-chart
dir="rtl"
label="السعر والطلبات"
[rows]="itemsArabic"
x="price"
y="orders"
name="item"
group="kind"
xLabel="السعر"
yLabel="الطلبات"
locale="ar-EG"
/>When to use something else
| If you need | Use |
|---|---|
| How one number changes over time | Line chart |
| Amounts to compare | Bar 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 number along the bottom. |
y | string | — | Required. The row field with the number up the side. |
size | string | — | The row field with a third number: the area of the bubble. |
group | string | — | The row field that sorts points into groups, up to four. |
name | string | — | The row field with the name of a point, in the tooltip and the table. |
nameLabels | boolean | false | Writes the name at each point. |
trend | boolean | false | The straight line that fits best. |
highlight | string | — | The group to bring forward; the others turn grey. |
xReferences | ChartReference[] | [] | Named levels along the bottom. |
yReferences | ChartReference[] | [] | Named levels up the side. |
xLabel | string | — | Names the bottom axis, and its column in the table. |
yLabel | string | — | Names the side axis, and its column. |
sizeLabel | string | — | Names the size, in the tooltip and the table. |
nameLabel | string | — | Names the column of names. |
groupLabel | string | — | Names the column of groups. |
xMin | number | — | Where the bottom axis starts. Defaults to fit the points. |
xMax | number | — | Where it ends. |
yMin | number | — | Where the side axis starts. Defaults to fit the points. |
yMax | number | — | Where it ends. |
formatX | (x: number) => string | — | Writes the number along the bottom. |
formatY | (y: number) => string | — | Writes the number up the side. |
formatSize | (size: number) => string | — | Writes the size. |
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. |
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.
- Groups differ by shape as well as colour, and the trend line is dashed.