Calm motion: animations on this site only fade, with no movement
Histogram
Raw values in round bins, as bars
Shows the shape of many values, for example how long people listen: where most values are, and whether there are two groups. For the spread of values in a few groups side by side, use the box plot.
Basic
| Range | Count |
|---|---|
| 0–5 | 77 |
| 5–10 | 56 |
| 10–15 | 36 |
| 15–20 | 35 |
| 20–25 | 27 |
| 25–30 | 24 |
| 30–35 | 11 |
| 35–40 | 27 |
| 40–45 | 82 |
| 45–50 | 25 |
valuesis a list of raw numbers. The chart counts them in bins of equal width. A value that is not a number is left out.binsis about how many bins (default 10). The edges are round numbers, so the real count can be a little different. A bin holds the values from its start up to its end, and the last bin also holds its end.- The bars touch, because the bins have no gaps between them. The edges of the bins are on the x axis. A hover on a bar shows its range and count.
colorsets the color of the bars, as a token name or any CSS color (defaultchart-1). The chart draws at the width of its container, andheightsets the height (default 240).- The chart is hidden from screen readers, and a table of the ranges and counts is read in its place.
labelnames the table, andformatsets the text of an edge. Change the column names withlabelsor a label pack:rangeandcount. - The chart is drawn as plain SVG. There is no chart library to install.
Usage
ts
import { BlessHistogram } from "blessing-ui";API
Props
| Name | Type | Default | Description |
|---|---|---|---|
values* | number[] | — | the raw values; the chart counts them in bins |
bins | number | 10 | about how many bins; the edges are round numbers |
color | string | "chart-1" | |
height | number | 240 | |
format | ((v: number) => string) | — | text for a bin edge, for example `(v) => v + " min"` |
label | string | "Chart" | names the chart and its table for screen readers |
labels | Partial<{ range: string; count: string; }> | — |