Histogram
How a list of numbers is spread: response times, order values, scores. The numbers are counted into bins of equal width and drawn as touching bars, with optional lines at the mean and the median. For one bar per category, use the bar chart.
Install
npx shadcn@latest add @thrum-pro/histogramThis is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.
Data shape
values: readonly (number | null)[]; // null is skipped
// bins(values, options) is exported too:
type HistogramBin = { x0: number; x1: number; count: number };[212, 187, 240, null, 1960, 233, 198, 205]Props
| Prop | Type | Default | Description |
|---|---|---|---|
values | readonly (number | null)[] | Required | The numbers to count. null and non-finite entries are skipped. |
label | string | Required | What the numbers measure. Read by screen readers and used as the table caption. |
binCount | number | Default log2(n) + 1 | About how many bins. Edges are rounded to 1, 2 or 5 times a power of ten, so the result can differ by a few. |
binWidth | number | – | The exact width of every bin, in the unit of the values. Wins over binCount. A width that would give more than 1,000 bins falls back to about 1,000. |
domain | readonly [number, number] | – | Only values in this range are counted, and the bins span exactly it. Values outside are left out of the counts and the markers. |
markers | readonly ("mean" | "median")[] | Default [] | Lines at the mean (long dashes) and the median (short dashes), each labelled with its value on its own row above the plot. |
format | Intl.NumberFormatOptions | Default compact | How values are written on the bottom axis, in the readout and in the data table. Counts are whole numbers. |
locale | string | Default "en-US" | Locale for number formatting. |
yAxis | boolean | Default true | Show count lines and their labels. |
xAxis | boolean | Default true | Show bin edges along the bottom. When they do not all fit, every second, third or nth edge is shown. |
color | string | Default var(--chart-1) | Any CSS colour for the bars. |
onActiveChange | (index: number | null) => void | – | Called with the index of the bin under the cursor, or null when the cursor leaves. |
sound | boolean | Default true | Play a tick as the cursor moves between bins, if the visitor has sound on. |
emptyLabel | string | Default "No data" | Text shown when there is nothing to count. |
className | string | – | Sets the size. The default is full width and 256 pixels tall. |
Motion and sound
Motion
- First draw: each bar grows from the zero line in 250 ms. Bars start 40 ms apart, and the whole entrance takes 550 ms at most however many bins there are.
- New values with the same number of bins: each bar moves to its new height in 400 ms with no overshoot. A different number of bins is drawn again at once.
- The cursor band and the readout follow the pointer on a stiff spring.
- Reduced motion: the chart appears complete, and data changes and the cursor move instantly.
Sound
- A soft tick each time the cursor lands on a different bin, at most one every 40 ms.
Sound is off until the visitor turns it on. Pass sound={false} to keep this component silent. How sound works
Accessibility
- The chart is one tab stop, exposed as a slider whose value text is the bin under the cursor, for example “200 ms–250 ms: 84”.
- A visually hidden table carries every bin's range and count. Its caption names the chart and gives the mean and median when they are drawn.
- Mean and median differ in dash pattern and in their written labels, not only in position. Each line has a ring of the background so it shows over the bars.
- The readout is a floating surface. Under frosted glass it turns translucent and keeps its text at 4.5:1.
| Keys | Action |
|---|---|
| Tab | Focus the chart. The cursor goes to the last bin. |
| ← → | Move the cursor one bin. |
| Home / End | Jump to the first or last bin. |
| Esc | Hide the cursor. |
Source
The source comes with Pro
TypeScript source · Copy-paste ready · MIT-compatible for client projects · Includes all dependencies
Files and dependencies
- Adds
components/ui/histogram.tsx- Packages
motion- Brings along
- Chart foundationsMotion tokensSound engineChart tooltip
Changelog
- 1.0.0 · 2026-12-03First release.