Skip to content

Histogram for React

A React histogram shows how a measure is spread, with automatic bins, an optional density curve and percentile markers. Pass values as a readonly number[] of raw measurements: the chart bins them for you.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/histogram.json

API latency

1,200 values, median 116 ms, mean 129 ms. Use the left and right arrow keys to read each bin.

SLO 300 ms

  • Histogram
  • HistogramTable
  • sortedValues
  • histogramBins
  • kernelDensity
  • +8 more
  • +5 more

Latency with percentiles

1,200 API response times. Drag the slider to re-bin: bars morph to the new edges. The dashed lines mark the median, p95 and an SLO of 300 ms; hover, tap or arrow through the bins.

API latency

Response times, this week

  • Requests
  • Density

p95 247 msSLO 300 ms

Density plot

bars={false} with density draws the smooth curve alone, on a gradient that fades to the baseline. Two peaks show at a glance: single items and bundles.

Order value

Share of orders, last 30 days

Files to copy

14 folders · 29 files · 4 packages
From theme/src/
  • components/charts/{histogram.tsx, chart-export-menu.tsx, chart-export.ts, chart-figure.tsx, chart-fit.tsx, chart-icons.tsx, chart-parts.tsx, chart-patterns.tsx, chart-pointer.tsx, chart-tip.tsx, chart-utils.ts, heatmap.tsx}
  • components/charts/chart-parts/
  • components/charts/heatmap/
  • components/charts/histogram/
  • components/charts/kits/
  • components/drawer/parts/sheet.tsx
  • components/kbd/
  • components/menu/
  • components/skeleton/
  • components/status-icons/
  • hooks/{use-controllable.ts, use-direction.ts, use-intersection.ts, use-latest.ts, use-media-query.ts, use-preferences.ts}
  • motion/tokens.ts
  • lib/{cn.ts, csv.ts, form.ts, glide-highlight.tsx, heading.ts, math.ts, popup-a11y.ts, popup-motion.ts, warn-once.ts}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/histogram.jsonRegistry item: histogram. The styles need the Tailwind v4 glass UI setup.
Packages
pnpm add @base-ui/react clsx motion tailwind-merge

Next.js: samples here pass functions (formatters, seriesLegend, a dashboard's load), so put them in a file that starts with "use client".

Shares, fixed bins

measure="percent" sizes bars by their share of the sample; bins={8} asks for about eight bins; snapped to round $25 edges, that makes ten.

Order value, binned

Share of orders in $25 bins

Props

PropTypeDefaultDescription
values (required)readonly number[]NoneThe raw sample, e.g. every request's latency. Non-finite values are ignored.
binsnumber | BinMethod"auto"A bin count, or a rule: "auto" (default), "sturges", "freedman-diaconis" or "scott".
domainreadonly [number, number]the data's extentRange to bin. Values outside it are left out.
niceBinsbooleantrueSnap bin edges to round numbers (the bin count lands near bins).
measure"count" | "percent""count"Height of a bar: the number of values, or their share of the sample.
barsbooleantrueDraw the bins. Turn off (with density) for a smooth density plot.
densitybooleanfalseOverlay a smooth density curve (Gaussian kernel density estimate).
bandwidthnumberSilverman's ruleSets the KDE bandwidth in data units.
markersreadonly HistogramMarker[][]Reference lines: "median", "mean", "p90", "p95", "p99", or { value, label }.
colorChartColor1Sets the palette slot (1–8) of the bars.
heightnumber280Height of the chart in px; the width follows the container.
xLabelstringNoneNames the value axis (shown under it and in the readout).
yLabelstringNoneNames the count axis (shown above it).
format((n: number) => string)formatCompact in localeFormats values (bin edges, markers).
formatCount((n: number) => string)formatCompact in localeFormats a bin count for the labels, tooltips and data table: takes the number, returns the text shown.
formatPercent((ratio: number) => string)percentages in localeFormats a share as text (0.12 → "12%").
localestring"en"Locale of the default number formats.
emptyStateReactNodeNoneShown when there is nothing to plot.
labelsPartial<HistogramLabels>defaultHistogramLabelsEvery other string, for translation: labels={{ roleDescription: "…" }}; omitted keys keep the English of defaultHistogramLabels. All 14 keys of HistogramLabels are listed in the key table under the props table.
aria-label (required)stringNoneNames the chart for assistive tech (required).
classNamestringNoneAdds extra classes to the outer element.
HistogramLabels keys and English defaults (14)
Pass any key in labels; the rest keep the defaults of defaultHistogramLabels.
KeyEnglish default
roleDescriptionhistogram
instructionsUse the left and right arrow keys to read each bin.
hintTap a bar to read its bin
countCount
shareShare
cumulative(edge) => `at or below ${edge}`
cumulativeHeaderCumulative
range(from, to) => `${from}–${to}`
summary(n, median, mean) => `${n} values, median ${median}, mean ${mean}.`
meanMean
medianMedian
percentile(p) => `p${p}`
binRange
noDataNo data

HistogramTable props

PropTypeDefaultDescription
format((n: number) => string)formatCompact in localeFormats values (bin edges, markers).
values (required)readonly number[]NoneThe raw sample, e.g. every request's latency. Non-finite values are ignored.
labelsPartial<HistogramLabels>defaultHistogramLabelsEvery other string, for translation: labels={{ roleDescription: "…" }}; omitted keys keep the English of defaultHistogramLabels. All 14 keys of HistogramLabels are listed in the key table under the props table.
localestring"en"Locale of the default number formats.
formatPercent((ratio: number) => string)percentages in localeFormats a share as text (0.12 → "12%").
domainreadonly [number, number]the data's extentRange to bin. Values outside it are left out.
binsnumber | BinMethod"auto"A bin count, or a rule: "auto" (default), "sturges", "freedman-diaconis" or "scott".
niceBinsbooleantrueSnap bin edges to round numbers (the bin count lands near bins).
xLabelstringNoneNames the value axis (shown under it and in the readout).
formatCount((n: number) => string)formatCompact in localeFormats a bin count for the labels, tooltips and data table: takes the number, returns the text shown.
captionstringNoneSets a visually hidden caption that names the table.

Keyboard

KeysAction
TabFocus the chart. It is one tab stop; the arrow keys then read it.
←/→ or ↓/↑Previous / next bin (← / → are mirrored in right-to-left).
Home/EndJump to the first / last bin.
EscapeClear the reading.

Accessibility

  • Keyboard and screen-reader users get a single focusable figure labelled by the chart title, with a short reading hint as its description; inside a ChartCard with a table view, aria-details links it to the table. Every value read is announced politely, once. Each move announces the bin's range, count, share and cumulative share.
  • HistogramTable is the table view: pair it with ChartCard's table prop (Chart / Table tabs) so every value can be read without color or sight.
  • Reduced motion: the bins appear at their final heights and data changes jump instead of morphing.

All exports on this page

  • Histogram — A distribution in bins: bars that touch (a 2px surface gap between neighbours: the bins are adjacent intervals, not categories).
  • HistogramTable — Every bin with its count, share and cumulative share: the colour-free twin of a Histogram.
  • defaultHistogramLabels — The built-in English strings of Histogram; spread it into your own labels and change what you need.
  • distributionStats — Summary of SORTED values for a box plot.
  • histogramBins — Bins SORTED values into equal-width intervals.
  • histogramLegend — Legend items for a histogram: the bins, plus the density curve when it is drawn over them.
  • kernelDensity — Gaussian kernel density of SORTED values, evaluated at each of at.
  • quantileSorted — The p-quantile (0–1) of SORTED values, linearly interpolated (R type 7, Excel PERCENTILE.INC).
  • sortedValues — The finite numbers of a list, sorted ascending (a new array; the input is untouched).
  • suggestedBinCount — How many bins a rule suggests for SORTED values.

When to use Histogram

  • Use it as a distribution chart for a raw sample, such as every request's latency or order value, with reference lines for the median, mean and p95 or p99.
  • Use density for a smooth kernel estimate over the bars, or turn bars off to get a pure density plot when you compare the shape of the sample with a theoretical curve.
  • Use measure percent when samples of different sizes sit side by side, so bar height is a share of the sample rather than a count.
  • Skip it when you have a few named categories rather than continuous numbers, where a Bar chart is right, or when you compare distributions across groups, where a Box plot fits better.
  • Pair it with ChartCard and HistogramTable for a text twin, a Slider to adjust the bin count, and Select to switch which metric is binned.

Frequently asked questions

48 charts pages in all: browse them on Charts.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .