Box plot (Pro)
ProIncluded in $99Several distributions on one axis, a row each: the middle half, the median, whiskers and outliers, with every point a click away.
On this page
Installation
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
import { BoxPlot } from "@/components/ui/chatcn/pro/box-plot"
<BoxPlot
title="Time to resolve, by queue"
groups={[
{ label: "Billing", values: billingHours },
{ label: "Bugs", values: bugHours },
]}
unit="h"
noun="tickets"
sort="ascending"
reference={{ value: 8, label: "8 h target" }}
variant="box" // or "swarm"
/>Pass raw values per group and the chart works out Tukey's box: quartiles, whiskers to the furthest value within one and a half box lengths, and dots for the rest. Rows run sideways so long group names read in full, and under 480 px each name moves above its row. Boxes are tinted and rounded with a crisp median line, whiskers end in caps and outliers are small rings. Every point packs each value under its box without overlap, which is the honest view when groups differ wildly in size. variant="swarm" drops the boxes and lays every value out as a beeswarm: each dot takes the free spot nearest its row's center line in value order, so the layout is the same on every render, rows grow with how crowded they are, and every row shares one dot size so a dot means one value everywhere. The middle half and median sit in a slim bar under each swarm. Groups over 400 values draw as a seeded strip instead, so a resize stays quick. reference runs a dashed amber line through every row with its label in a pill. sort orders rows by median. Point at a row, or move with the arrow keys, for a card with its five numbers, count and outliers, placed above or below the row so it never covers it. boxStats and swarmOffsets are exported for working the same numbers out elsewhere.
Examples
States
Props
| Prop | Type | Notes |
|---|---|---|
groups | BoxPlotGroup[] | { label, values } |
reference | { value, label? } | A line through every row |
sort | "none" | "ascending" | "descending" | By median. Default none |
variant | "box" | "swarm" | Boxes with a points switch, or a beeswarm. Default box |
defaultView | "box" | "points" | Starting view of the box variant. Default box |
noun | string | What a value is, for counts |
unit, valueFormat, locale | Formatting | |
height | number | Default fits the rows |
loading, error, onRetry | ||
labels | Partial<BoxPlotLabels> | Every string, for translation |
Keyboard
| Key | Action |
|---|---|
| Tab | Focus the chart, then the view switch |
| Arrow keys | Previous or next group |
| Home, End | First or last group |
Accessibility
- The chart is summarized in words with the lowest and highest medians, with a table of every group's five numbers and outliers.
- The readout says what the box, line and rings (or dots, for the swarm) mean before anything is pointed at.
Motion
Boxes open from the median and whiskers follow once over 760 ms; swarm dots spread out from each row's center line. Under reduced motion they appear drawn.