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.jsonAPI latency
SLO 300 ms
HistogramHistogramTablesortedValueshistogramBinskernelDensity- +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
import { ChartCard } from "@/components/sheenui/charts/chart-parts/chart-card";
import { HistogramTable, Histogram } from "@/components/sheenui/charts/histogram";
import { histogramLegend } from "@/components/sheenui/charts/histogram/model";
// Package build (after the first npm release, or a packed tarball): import { ChartCard, histogramLegend, HistogramTable, Histogram } from "@sheenui/theme";
// Response times in ms (a sample; yours is the full list)
const latencies: number[] = [
84, 92, 97, 101, 104, 108, 111, 113, 116, 118, 121, 124, 127, 131, 135, 140,
146, 153, 161, 172, 188, 206, 233, 271, 342, 96, 109, 119, 129, 150,
];
const ms = (n: number) => Math.round(n) + " ms";
export function Example() {
return (
<ChartCard
title="API latency"
description="Response times, this week"
legend={histogramLegend({ density: true, labels: { bins: "Requests" } })}
table={<HistogramTable values={latencies} bins="auto" format={ms} caption="API latency by range" />}
>
<Histogram
values={latencies}
bins="auto"
density
markers={["median", "p95", { value: 300, label: "SLO" }]}
format={ms}
xLabel="Response time"
aria-label="Distribution of API response times"
/>
</ChartCard>
);
}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
import { Histogram } from "@/components/sheenui/charts/histogram";
// Package build (after the first npm release, or a packed tarball): import { Histogram } from "@sheenui/theme";
// Basket sizes in $ (a sample; yours is the full list)
const orderValues: number[] = [
38, 42, 45, 47, 51, 36, 58, 44, 49, 62, 33, 54, 41, 46, 139, 148, 126, 155, 171, 133,
144, 118, 162, 150, 52, 40, 143, 137, 48, 56,
];
const usd = (n: number) => "$" + Math.round(n);
export function Example() {
return (
<Histogram
values={orderValues}
bars={false}
density
measure="percent"
markers={["median"]}
format={usd}
color={3}
aria-label="Distribution of order values"
/>
);
}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.tsxcomponents/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.tslib/{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
import { Histogram } from "@/components/sheenui/charts/histogram";
// Package build (after the first npm release, or a packed tarball): import { Histogram } from "@sheenui/theme";
// Basket sizes in $ (a sample; yours is the full list)
const orderValues: number[] = [
38, 42, 45, 47, 51, 36, 58, 44, 49, 62, 33, 54, 41, 46, 139, 148, 126, 155, 171, 133,
144, 118, 162, 150, 52, 40, 143, 137, 48, 56,
];
const usd = (n: number) => "$" + Math.round(n);
export function Example() {
return (
<Histogram
values={orderValues}
bins={8}
measure="percent"
markers={["mean"]}
format={usd}
color={7}
aria-label="Orders by value, in $25 bins"
/>
);
}Props
HistogramLabels keys and English defaults (14)
HistogramTable props
Keyboard
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
Related pages
48 charts pages in all: browse them on Charts.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .