Chapter 12 Charts
Gauge chart
One level inside a known range, as a ring. The value is written in the middle and read with the name, so the colour only repeats it. For a list of levels use Meter: it takes less room.
import { GaugeChartComponent } 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.0A level
Three quarters of a ring, with the ends of the scale.
Delivery score
<ui-gauge-chart label="Delivery score" [value]="72" />Half a ring
For a short, wide box.
Delivery score, half
<ui-gauge-chart
label="Delivery score, half"
[value]="72"
shape="half"
[height]="220"
/>A whole ring
For progress towards all of something.
Orders delivered
<ui-gauge-chart
label="Orders delivered"
[value]="86"
shape="ring"
valueText="86%"
tone="success"
/>Zones
Named parts of the scale. The name of the zone is written under the value.
Delivery score, in zones
- Low: 0 – 50
- Fair: 50 – 80
- Good: 80 – 100
const zones = [
{ from: 0, to: 50, label: 'Low', tone: 'danger' },
{ from: 50, to: 80, label: 'Fair', tone: 'warning' },
{ from: 80, to: 100, label: 'Good', tone: 'success' },
];
<ui-gauge-chart
label="Delivery score, in zones"
[value]="64"
[zones]="zones"
/>A target
A mark across the ring.
Delivery score and the target
const goal = { value: 80, label: 'Target' };
<ui-gauge-chart
label="Delivery score and the target"
[value]="64"
[target]="goal"
/>Zones and a target
Delivery score, zones and target
- Low: 0 – 50
- Fair: 50 – 80
- Good: 80 – 100
<ui-gauge-chart
label="Delivery score, zones and target"
[value]="91"
[zones]="zones"
[target]="goal"
shape="half"
[height]="240"
/>Your own range
Any range and any words.
Storage
<ui-gauge-chart
label="Storage"
[value]="7.2"
[max]="10"
valueText="7.2 GB"
[formatValue]="gigabytes"
tone="warning"
/>Tones
You choose the tone from the value: the gauge does not guess.
SMS credit
<ui-gauge-chart
label="SMS credit"
[value]="12"
tone="danger"
[height]="220"
/>Without the ends
Delivery score, plain
<ui-gauge-chart
label="Delivery score, plain"
[value]="72"
[ends]="false"
[height]="220"
/>Side by side
For two or three levels.
Cairo
Giza
Tanta
<ui-gauge-chart label="Cairo" [value]="91" [height]="180" />A value that changes
Live score
- Low: 0 – 50
- Fair: 50 – 80
- Good: 80 – 100
<ui-gauge-chart label="Live score" [value]="score" [zones]="zones" />Loading
Keeps its place while the value arrives.
Score, loading
Loading
<ui-gauge-chart label="Score, loading" [value]="0" loading [height]="160" />In Arabic
Fills from right to left, with Arabic digits.
تقييم التوصيل
- منخفض: ٠ – ٥٠
- متوسط: ٥٠ – ٨٠
- جيد: ٨٠ – ١٠٠
<ui-gauge-chart
dir="rtl"
label="تقييم التوصيل"
[value]="64"
[zones]="zonesArabic"
locale="ar-EG"
/>In Arabic, half a ring
تقييم التوصيل، نصف دائرة
<ui-gauge-chart
dir="rtl"
label="تقييم التوصيل، نصف دائرة"
[value]="64"
shape="half"
[height]="220"
locale="ar-EG"
/>When to use something else
Inputs
| Name | Type | Default | What it does |
|---|---|---|---|
label | string | — | Required. Names the chart, above it and for screen readers. |
value | number | — | Required. The level now. |
min | number | 0 | The lowest level. |
max | number | 100 | The highest level. |
shape | 'arc' | 'half' | 'ring' | 'arc' | Three quarters of a ring, half, or all of it. |
valueText | string | — | The value in words. Defaults to the number. |
tone | 'neutral' | 'success' | 'warning' | 'danger' | 'neutral' | Colour of the fill, when there are no zones. |
zones | GaugeZone[] | [] | Named parts of the scale: from, to, label and tone. |
target | { value, label } | — | A mark across the ring. |
ends | boolean | true | The lowest and highest value at the ends. |
formatValue | (value: number) => string | — | Writes a value. |
valueLabel | string | — | Names the column of the table. Defaults to Value. |
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. |
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. |
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. |
Keyboard and screen readers
| Keys | What they do |
|---|---|
| Tab | Reach the gauge, then its next control. |
- A named graphic, read in one go.
- The same numbers are always there as a real table.
- The value and its zone are part of the name, so they are read at once.