Chapter 12 Charts
Histogram
How many values fall in each range: delivery times, order sizes, ages. The ranges have round edges, and one button shows them as a table.
import { HistogramChartComponent } 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.0Ranges
One row per value; the chart counts them. Press Tab and use the arrow keys.
Delivery times
const times = [{ minutes: 24 }, { minutes: 31 }, { minutes: 26 }];
<ui-histogram-chart label="Delivery times" [rows]="times" value="minutes" />The middle
Half of the values are on each side.
Delivery times, with the median
<ui-histogram-chart
label="Delivery times, with the median"
[rows]="times"
value="minutes"
[median]="true"
/>More bars
About how many; the edges stay round.
Delivery times, in detail
<ui-histogram-chart
label="Delivery times, in detail"
[rows]="times"
value="minutes"
[bins]="20"
/>Fewer bars
Delivery times, in short
<ui-histogram-chart
label="Delivery times, in short"
[rows]="times"
value="minutes"
[bins]="4"
/>A limit
A named line across the ranges.
Delivery times and the promise
<ui-histogram-chart
label="Delivery times and the promise"
[rows]="times"
value="minutes"
[references]="promise"
/>Named axes and formats
Delivery times, named
<ui-histogram-chart
label="Delivery times, named"
[rows]="times"
value="minutes"
xLabel="Minutes"
yLabel="Deliveries"
[formatValue]="minutes"
/>Open a range
Click a bar, or press Enter on it. The row has from, to and count.
Open a range
Nothing picked yet.
<ui-histogram-chart
label="Open a range"
[rows]="times"
value="minutes"
(rowSelect)="open($event)"
/>Loading
Keeps its place while the rows arrive.
Loading
Loading
<ui-histogram-chart
label="Loading"
[rows]="none"
value="minutes"
loading
[height]="160"
/>Nothing yet
Says so in words.
Nothing yet
Nothing to show yet
<ui-histogram-chart
label="Nothing yet"
[rows]="none"
value="minutes"
emptyMessage="Nothing to show yet"
[height]="160"
/>In Arabic
Low numbers are on the right.
أوقات التوصيل
<ui-histogram-chart
dir="rtl"
label="أوقات التوصيل"
[rows]="timesArabic"
value="minutes"
locale="ar-EG"
[median]="true"
/>When to use something else
| If you need | Use |
|---|---|
| To compare groups | Box plot |
| Amounts with names | Bar chart |
| Two numbers that go together | Scatter chart |
Inputs
| Name | Type | Default | What it does |
|---|---|---|---|
label | string | — | Required. Names the chart, above it and for screen readers. |
rows | object[] | — | Required. The data. |
value | string | — | Required. The row field with the number to count. |
bins | number | — | About how many bars. Defaults to a number that suits the data. |
median | boolean | false | Marks the middle value. |
references | ChartReference[] | [] | Named levels: value and label. |
xLabel | string | — | Names the axis of ranges, and the first table column. |
yLabel | string | — | Names the axis of counts. Defaults to Count in the table. |
formatValue | (value: number) => string | — | Writes a number on the axis of ranges. |
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. |
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.
- Each range and its count are announced together.