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

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.

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

Terminal
pnpm add @tanstack/charts@1.5.0

Ranges

One row per value; the chart counts them. Press Tab and use the arrow keys.

Delivery times
Angular
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
Angular
<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
Angular
<ui-histogram-chart
  label="Delivery times, in detail"
  [rows]="times"
  value="minutes"
  [bins]="20"
/>

Fewer bars

Delivery times, in short
Angular
<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
Angular
<ui-histogram-chart
  label="Delivery times and the promise"
  [rows]="times"
  value="minutes"
  [references]="promise"
/>

Named axes and formats

Delivery times, named
Angular
<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.

Angular
<ui-histogram-chart
  label="Open a range"
  [rows]="times"
  value="minutes"
  (rowSelect)="open($event)"
/>

Loading

Keeps its place while the rows arrive.

Loading

Loading

Angular
<ui-histogram-chart
  label="Loading"
  [rows]="none"
  value="minutes"
  loading
  [height]="160"
/>

Nothing yet

Says so in words.

Nothing yet

Nothing to show yet

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

أوقات التوصيل
Angular
<ui-histogram-chart
  dir="rtl"
  label="أوقات التوصيل"
  [rows]="timesArabic"
  value="minutes"
  locale="ar-EG"
  [median]="true"
/>

When to use something else

If you needUse
To compare groupsBox plot
Amounts with namesBar chart
Two numbers that go togetherScatter chart

Inputs

NameTypeDefaultWhat it does
labelstring — Required. Names the chart, above it and for screen readers.
rowsobject[] — Required. The data.
valuestring — Required. The row field with the number to count.
binsnumber — About how many bars. Defaults to a number that suits the data.
medianbooleanfalseMarks the middle value.
referencesChartReference[][]Named levels: value and label.
xLabelstring — Names the axis of ranges, and the first table column.
yLabelstring — Names the axis of counts. Defaults to Count in the table.
formatValue(value: number) => string — Writes a number on the axis of ranges.
descriptionstring — A line of text under the name.
hideLabelbooleanfalseKeeps the name for screen readers only.
heightnumber280In pixels. The width follows the box around it.
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.
  • Each range and its count are announced together.