Skip to content
ChartslibraryUI
Get Pro
By Boris Marino · Updated 2026-12-01

shadcn Histogram: Bins, Pitfalls and a Free Component

The shadcn/ui charts have bar charts but no histogram, and a bar chart is not a histogram. A bar chart compares categories you already have. A histogram takes raw numbers (deal sizes, response times, session lengths), groups them into ranges and counts each range, so you can see the shape: where most values sit, how wide the spread is, and whether there's a long tail.

Building one on a bar chart means writing the binning yourself, and that's where the mistakes are. This guide lists them and shows how to install a free histogram in a shadcn project.

When to use a histogram

  • "What's a typical deal size?" The histogram shows that most deals are small and a few are huge, which an average hides.
  • Response or load times: is the slow tail getting longer?
  • Session length, order value, age, tenure: any time the question is "how are these values spread out?"

To compare spreads across groups (plans, regions), use a box plot or a strip plot. For a single summary number, a KPI tile.

The checklist

  1. Sensible default bins. Too few bins hide the shape; too many turn it into noise. A good default comes from the data (the Freedman–Diaconis rule), not a fixed 10.
  2. Round bin edges. "$20K-$25K" is readable. "$19,874-$24,843" is not, and neither is floating-point noise like 0.30000000000000004.
  3. Bars sit edge to edge. The ranges are continuous, so bars are separated by a hairline at most, not the wide gaps of a bar chart. Wide gaps make it look like categories.
  4. Empty bins stay in. A range with zero values is information. Dropping it squeezes the axis and changes the shape.
  5. Missing values are counted, not hidden. If 12 rows have no value, the reader should know.
  6. A warning when there's too little data. With 15 observations, the shape is mostly chance.
  7. A median marker. On skewed data (most business data), the median is the typical value; the mean is pulled by the tail.

Install the free histogram

ChartslibraryUI's histogram is free (MIT). Install it with the shadcn CLI:

pnpm dlx shadcn@latest add @chartslibraryui/histogram

or by URL: npx shadcn@latest add https://chartslibraryui.com/r/histogram.json.

Pass the raw values (numbers, or rows with a value key):

<Histogram
  title="Most deals are under $25K, with a long tail"
  subtitle="Closed-won deal size, last four quarters"
  data={dealSizes}
  format="currency"
  countLabel="Deals"
/>

What it does for you: Freedman–Diaconis bins (between 5 and 40) with rounded edges, a median line by default (marker="mean" or "none" to change it), notes for missing and non-numeric values, and a warning under 20 observations. Set bins for an approximate count or binWidth for exact ranges, such as one-minute buckets:

<Histogram
  title="Typical sessions last 5 to 10 minutes"
  data={sessionMinutes}
  binWidth={1}
  countLabel="Sessions"
/>

Keep histograms honest

  • Say what's counted in the subtitle and with countLabel: deals, sessions, tickets.
  • Don't cut the tail to make it pretty. If outliers matter, keep them and say so; if you exclude them, say that.
  • Compare two histograms on the same bins and axis, or use small multiples.

Try the free charts in your app

35 charts, MIT, one command each.

More

Sign in to ChartslibraryUI

New here? The same step creates your account.

Continue with Google
or

No password needed. Bought Pro? Use the email you paid with and your license is there. By signing in you agree to the Terms and Privacy policy.