Skip to content
Sign upPro
DataHistogram chartMenu

Histogram chart (Pro)

ProIncluded in $99

A distribution that answers how many and how bad the tail is: round bins with a width slider, percentile lines and a target with the share past it.

ProA day of checkout API response times against an 800 ms target. Drag the slider to change the bin width.

Installation

$ pnpm dlx shadcn@latest add @chatcn-pro/histogram-chart

Needs chatcn Pro

This command works with a Pro license, along with every Pro component.

Or start free: sign up and get three Pro components on us, with a new one every month.

Usage

tsx
import { HistogramChart } from "@/components/ui/chatcn/pro/histogram-chart"

<HistogramChart
  title="Checkout API response time"
  values={responseTimes}
  unit="ms"
  valueFormat="integer"
  markers={["median", "p90", "p99"]}
  headline="p99"
  target={{ value: 800, label: "the 800 ms target" }}
/>

Pass the raw values and the chart bins them. Bin widths are always round, 1, 2, 2.5 or 5 times a power of ten, starting near the Freedman Diaconis rule; the slider steps through the round widths from coarse to fine, so a bin never reads 37.4 to 74.8. Bins are rounded with small gaps and a soft vertical gradient; they sit as a quiet tint and the bin you point at takes the full color. Median, mean and percentile lines carry their values in pills above the plot, sliding aside or stepping to a second row when two would touch. A target draws a red line with its own pill and hatches the bad side (above by default, bad: "below" for things like conversion), and the readout says what share is past it. headline sets one statistic large under the title, with the share past the target in a chip beside it. variant="density" steps the bins back and lays a smoothed density curve over them, with a soft fill, for reading the shape. Point at a bin, or walk them with the arrow keys, for a card with its range, count, share and the share at or below it. The table lists every bin. kernelDensity is exported for drawing the same curve elsewhere.

Examples

States

ProOrder values in a narrow frame with fixed bins, loading, and a failed load.

Props

PropTypeNotes
valuesnumber[]Raw values; non finite ones are dropped
markersHistogramMarker[]mean, median, p90, p95, p99. Default median and p90
target{ value, label?, bad? }A limit with its bad side hatched
variant"bars" | "density"Density lays a smoothed curve over quiet bins
headlineHistogramMarkerOne statistic set large, with the share past the target
binWidth, defaultBinWidth, onBinWidthChangenumberDefault a round width near the Freedman Diaconis rule
fixedBinsbooleanHides the slider
unit, valueFormat, currency, localeFormatting
heightnumberDefault 240
loading, error, onRetry
labelsPartial<HistogramChartLabels>Every string, for translation

Keyboard

KeyAction
TabFocus the chart, then the slider
Arrow left, rightPrevious or next bin
Home, EndFirst or last bin

Accessibility

  • The chart is summarized in words with the count, the range and the median, with a table of every bin.
  • The slider reads the bin width with its unit.
  • The zone past the target is hatched as well as tinted, and the share is in words.

Motion

Bars grow from the baseline once over 760 ms with a short left to right stagger, the density curve draws in, and the pills fade in with them. Under reduced motion they appear drawn.