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

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.

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

Terminal
pnpm add @tanstack/charts@1.5.0

Two numbers

Each point is one thing. Press Tab and use the arrow keys to read each one.

Price and orders
Angular
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.

Price and orders by kind
  • Drinks
  • Food
  • Sweets
  • Offers
Angular
<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.

Price, orders and profit
Angular
<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

Price, orders and profit by kind
  • Drinks
  • Food
  • Sweets
  • Offers
Angular
<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.

Price and orders, with the trend
Angular
<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.

Offers and drinks, named
Angular
<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.

Price and orders, divided
Angular
<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.

Price and orders, sweets
  • Drinks
  • Food
  • Sweets
  • Offers
Angular
<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.

Price and orders, pick the kinds
Angular
<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

Size and time of 160 orders
Angular
<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.

Price and orders, from zero
Angular
<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.

Price and orders, open one

Nothing picked yet.

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

Orders, loading

Loading

Angular
<ui-scatter-chart
  label="Orders, loading"
  [rows]="none"
  x="price"
  y="orders"
  loading
  [height]="160"
/>

Nothing yet

Says so in words.

Orders, none yet

No orders yet

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

السعر والطلبات
  • مشروبات
  • طعام
  • حلويات
Angular
<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 needUse
How one number changes over timeLine chart
Amounts to compareBar 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 number along the bottom.
ystring — Required. The row field with the number up the side.
sizestring — The row field with a third number: the area of the bubble.
groupstring — The row field that sorts points into groups, up to four.
namestring — The row field with the name of a point, in the tooltip and the table.
nameLabelsbooleanfalseWrites the name at each point.
trendbooleanfalseThe straight line that fits best.
highlightstring — The group to bring forward; the others turn grey.
xReferencesChartReference[][]Named levels along the bottom.
yReferencesChartReference[][]Named levels up the side.
xLabelstring — Names the bottom axis, and its column in the table.
yLabelstring — Names the side axis, and its column.
sizeLabelstring — Names the size, in the tooltip and the table.
nameLabelstring — Names the column of names.
groupLabelstring — Names the column of groups.
xMinnumber — Where the bottom axis starts. Defaults to fit the points.
xMaxnumber — Where it ends.
yMinnumber — Where the side axis starts. Defaults to fit the points.
yMaxnumber — 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.
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.
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.
  • Groups differ by shape as well as colour, and the trend line is dashed.