Skip to content

Box Plot and Violin Chart for React

A React box plot compares distributions across groups; the violin variant shows the full shape, so two-peaked groups stand out. Pass data as readonly BoxPlotGroup[]: one box per group, in order.

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

Page load by region

Use the left and right arrow keys to move between groups, and up and down to read a group's outliers.

  • BoxPlot
  • BoxPlotTable
  • boxPlotStats
  • defaultBoxPlotLabels
  • +2 more

Box and whiskers

Page-load times in five regions, 240 visits each, with the mean as a diamond. Switch the whiskers to min–max and the outliers fold into them. Arrow between regions; up and down step through a region's outliers.

Page load by region

Last 7 days, 240 visits per region

Violin

variant="violin" draws each group's density around a slim box. The Free plan has two peaks, casual and power users, which a box alone would hide.

Weekly active minutes

By plan

Precomputed, sideways, one group emphasized

Pass a summary when you only have the statistics. orientation="horizontal" lays groups out as rows; a group's own color picks it out from the rest.

Delivery time

Days from dispatch, by carrier

Files to copy

15 folders · 30 files · 4 packages
From theme/src/
  • components/charts/{box-plot.tsx, 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/box-plot/
  • 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/box-plot.jsonRegistry item: box-plot. 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".

Props

PropTypeDefaultDescription
data (required)readonly BoxPlotGroup[]NoneOne box per group, in order.
variant"box" | "violin""box""box": box and whiskers. "violin": the density shape with a slim box inside.
orientation"horizontal" | "vertical" | "auto""auto""auto" draws upright boxes, and turns them sideways on narrow charts or when group names wouldn't fit.
whiskernumber | "minmax"1.5Whisker reach in IQRs (Tukey: 1.5): points beyond are outliers. "minmax" reaches the extremes.
showMeanbooleanfalseMark each group's mean with a small diamond.
includeZerobooleanfalseKeep 0 on the value axis.
bandwidthnumberSilverman's rule per groupKDE bandwidth of the violins, in data units.
colorChartColor1Palette slot (1–8) of every box (groups can override).
heightnumber300Height of an upright chart. Sideways charts grow with the number of groups.
valueLabelstringNoneNames the value axis.
format((n: number) => string)formatCompact in localeFormats a value for the axis, tooltips and data table: takes the number, returns the text shown.
localestring"en"Locale of the default number format.
emptyStateReactNodeNoneShown when there is nothing to plot.
labelsPartial<BoxPlotLabels>defaultBoxPlotLabelsEvery other string, for translation: labels={{ roleDescription: "…" }}; omitted keys keep the English of defaultBoxPlotLabels. All 17 keys of BoxPlotLabels 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.
BoxPlotLabels keys and English defaults (17)
Pass any key in labels; the rest keep the defaults of defaultBoxPlotLabels.
KeyEnglish default
roleDescriptionbox plot
instructions({ horizontal }) => horizontal ? "Use the up and down arrow keys to move between groups, and left and right...
hintTap a group to read it
medianMedian
quartilesMiddle 50%
whiskersWhiskers
meanMean
countValues
outliersOutliers
outlierOutlier
minMin
maxMax
q1Q1
q3Q3
groupGroup
between(low, high) => `${low}–${high}`
noDataNo data

BoxPlotTable props

PropTypeDefaultDescription
data (required)readonly BoxPlotGroup[]NoneOne box per group, in order.
format((n: number) => string)formatCompact in localeFormats a value for the axis, tooltips and data table: takes the number, returns the text shown.
labelsPartial<BoxPlotLabels>defaultBoxPlotLabelsEvery other string, for translation: labels={{ roleDescription: "…" }}; omitted keys keep the English of defaultBoxPlotLabels. All 17 keys of BoxPlotLabels are listed in the key table under the props table.
localestring"en"Locale of the default number format.
whiskernumber | "minmax"1.5Whisker reach in IQRs (Tukey: 1.5): points beyond are outliers. "minmax" reaches the extremes.
captionstringNoneHidden caption that names the table for screen readers.
classNamestringNoneAdds extra classes to the outer element.

Keyboard

KeysAction
TabFocus the chart. It is one tab stop; the arrow keys then read it.
Arrow keysAlong the group axis: move between groups. Along the value axis: step through the focused group's outliers.
Home/EndJump to the first / last group.
EscapeClear the reading.

Accessibility

  • The figure takes focus as one stop and is named by its aria-label, the chart title. A one-line hint explains the keys, and a ChartCard table view is linked through aria-details. Values are announced politely, once per move. Each move announces the group's statistics.
  • BoxPlotTable is the table view: pair it with ChartCard's table prop (Chart / Table tabs) so every value can be read without color or sight. It lists n, quartiles, median, mean and outliers.
  • With reduced motion on, the boxes and whiskers start at their final values and a data change jumps straight to the new state.

All exports on this page

  • BoxPlot — Box and whisker plots (or violins) for comparing distributions across groups: the box spans the middle 50% (Q1–Q3).
  • BoxPlotTable — Every group's statistics in text: n, min, quartiles, median, max, mean and the outliers.
  • boxPlotStats — Statistics for every group: computed from raw values, or taken from summary.
  • defaultBoxPlotLabels — The built-in English strings of BoxPlot; spread it into your own labels and change what you need.

When to use the box plot and violin chart

  • Use it as a box and whisker chart to compare latency, session length or delivery time across plans or regions, where the middle 50 percent, the median and the outliers matter more than any single average.
  • Use the violin variant when the shape of each distribution matters, such as a bimodal response-time pattern, since it draws a kernel density around a slim box instead of just five numbers.
  • Feed it precomputed statistics through the summary field when your backend already returns quartiles, whiskers and sample size, so the browser does not need the raw sample.
  • Skip it when you have a single group, where a Histogram shows the distribution directly, or when every individual observation should stay visible, which a Beeswarm handles better.
  • Pair it with ChartCard and BoxPlotTable, which lists n, quartiles, median, mean and outliers as text, and with a SegmentedControl to switch between the box and violin variants.

Frequently asked questions

48 charts pages in all: browse them on Charts.

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