Skip to content
Thrum

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/histogram

This is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.

Data shape

Type
values: readonly (number | null)[]; // null is skipped

// bins(values, options) is exported too:
type HistogramBin = { x0: number; x1: number; count: number };
Sample
[212, 187, 240, null, 1960, 233, 198, 205]

Props

PropTypeDefaultDescription
valuesreadonly (number | null)[]RequiredThe numbers to count. null and non-finite entries are skipped.
labelstringRequiredWhat the numbers measure. Read by screen readers and used as the table caption.
binCountnumberDefault log2(n) + 1About how many bins. Edges are rounded to 1, 2 or 5 times a power of ten, so the result can differ by a few.
binWidthnumber–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.
domainreadonly [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.
markersreadonly ("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.
formatIntl.NumberFormatOptionsDefault compactHow values are written on the bottom axis, in the readout and in the data table. Counts are whole numbers.
localestringDefault "en-US"Locale for number formatting.
yAxisbooleanDefault trueShow count lines and their labels.
xAxisbooleanDefault trueShow bin edges along the bottom. When they do not all fit, every second, third or nth edge is shown.
colorstringDefault 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.
soundbooleanDefault truePlay a tick as the cursor moves between bins, if the visitor has sound on.
emptyLabelstringDefault "No data"Text shown when there is nothing to count.
classNamestring–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.
KeysAction
TabFocus the chart. The cursor goes to the last bin.
← →Move the cursor one bin.
Home / EndJump to the first or last bin.
EscHide the cursor.

Source

SourcePro

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. 1.0.0 · 2026-12-03First release.

Loading index…

Keyboard shortcuts

/Ctrl KSearch components, docs and actions
?Show this list
AAppearance studio
SSound on or off
MFull or reduced motion
TTheme: auto, light, dark
GSurface: solid or frosted
BBackdrop photograph (under glass)
CCorner radius: square to round
RReplay the demo, on a component page
DDraw new data, on a component page
←→HomeEndMove the cursor in a focused chart
EscClose a dialog, or leave a chart cursor