Documentation / Charts
BoxPlot
What a mean hides: median, quartiles, whiskers and isolated observations. A bar chart of means claims two categories are alike; the box plot shows that one of them has a long tail.
The whiskers stop at the furthest observation still within 1.5 interquartile ranges (Tukey’s rule, adjustable through whisker), never at the extremes: it is the only way an outlier can show at all. Two ways to supply the data:
values: an array of raw observations per category. The component computes quartiles and outliers, and can mark the mean (showMean).quantiles: a summary already computed (server-side). No outlier is drawn: the summary cannot tell what they are.
One box per category; to compare two groups, use ChartFacets. Client component ("use client").
Examples
Distribution by team
values names the field holding the observations; the isolated points are the ones falling outside the whiskers.
import { BoxPlot } from "@synertech/ui";
const teams = [
{ team: "Backend", durations: [9, 12, 14, 15, 16, 17, 18, 18, 19, 21, 22, 24, 27, 88, 94] },
{ team: "Frontend", durations: [8, 10, 11, 12, 12, 13, 13, 14, 15, 15, 16, 18] },
{ team: "Données", durations: [14, 21, 26, 29, 32, 34, 35, 38, 41, 45, 52, 140] },
{ team: "Mobile", durations: [11, 15, 18, 20, 22, 24, 25, 27, 30, 33, 38] },
];
export function Basic() {
return (
<BoxPlot
data={teams}
x={{ key: "team" }}
values="durations"
y={{ label: "Durée de traitement (min)" }}
title="Durée de traitement des tickets"
height={320}
/>
);
}Mean and median
showMean adds a diamond beside the median line: the gap between the two is the shape of the tail.
import { BoxPlot } from "@synertech/ui";
const teams = [
{ team: "Backend", durations: [9, 12, 14, 15, 16, 17, 18, 18, 19, 21, 22, 24, 27, 88, 94] },
{ team: "Frontend", durations: [8, 10, 11, 12, 12, 13, 13, 14, 15, 15, 16, 18] },
{ team: "Données", durations: [14, 21, 26, 29, 32, 34, 35, 38, 41, 45, 52, 140] },
{ team: "Mobile", durations: [11, 15, 18, 20, 22, 24, 25, 27, 30, 33, 38] },
];
export function WithMean() {
return (
<BoxPlot
data={teams}
x={{ key: "team" }}
values="durations"
showMean
referenceLines={[{ value: 30, label: "Objectif 30 min" }]}
title="Durée de traitement des tickets"
height={320}
/>
);
}Precomputed summary, horizontal
quantiles reads five already-aggregated fields (here the percentiles from a time-series database). orientation="horizontal" leaves room for long names.
import { BoxPlot } from "@synertech/ui";
export function Precomputed() {
return (
<BoxPlot
data={[
{ route: "/api/search", p5: 40, p25: 92, p50: 128, p75: 210, p95: 620 },
{ route: "/api/cart", p5: 18, p25: 41, p50: 61, p75: 96, p95: 210 },
{ route: "/api/checkout", p5: 96, p25: 168, p50: 214, p75: 410, p95: 1180 },
{ route: "/api/profile", p5: 12, p25: 24, p50: 38, p75: 62, p95: 130 },
]}
x={{ key: "route" }}
quantiles={{ min: "p5", q1: "p25", median: "p50", q3: "p75", max: "p95" }}
orientation="horizontal"
y={{ label: "Latence (ms)" }}
title="Latence par route"
description="Moustaches aux 5ᵉ et 95ᵉ centiles"
/>
);
}Box detail
onBoxClick receives the computed statistics (stats) and the mean; the data table (tableView) gives the five figures of each box.
import { useState } from "react";
import { BoxPlot, type BoxPlotBox } from "@synertech/ui";
const teams = [
{ team: "Backend", durations: [9, 12, 14, 15, 16, 17, 18, 18, 19, 21, 22, 24, 27, 88, 94] },
{ team: "Frontend", durations: [8, 10, 11, 12, 12, 13, 13, 14, 15, 15, 16, 18] },
{ team: "Données", durations: [14, 21, 26, 29, 32, 34, 35, 38, 41, 45, 52, 140] },
{ team: "Mobile", durations: [11, 15, 18, 20, 22, 24, 25, 27, 30, 33, 38] },
];
export function Inspect() {
const [box, setBox] = useState<BoxPlotBox | null>(null);
return (
<div className="flex flex-col gap-3">
<BoxPlot
data={teams}
x={{ key: "team" }}
values="durations"
tableView="toggle"
format={(value) => `${Math.round(value)} min`}
title="Durée de traitement par équipe"
onBoxClick={setBox}
/>
{box?.stats ? (
<p className="text-sm text-gray-600 dark:text-gray-300">
{box.label} : médiane {box.stats.median} min, {box.stats.outliers.length} valeur(s)
aberrante(s)
</p>
) : null}
</div>
);
}API reference
Components
What a mean hides.
Median, quartiles, whiskers and the observations that fall outside them. A bar of averages says two categories are alike; a box plot is what shows that one of them is two populations wearing a trench coat.
The whiskers stop at the furthest observation within 1.5 interquartile ranges — Tukey's rule — rather than at the extremes. Whiskers drawn to the extremes cannot show an outlier at all: the point that matters most becomes the end of a line like any other. That needs the observations, so a chart given a precomputed summary draws no outlier and says nothing it cannot know.
One box per category: comparing two groups side by side is ChartFacets with a panel each, which keeps them on a shared scale without asking the reader to hold two colour legends at once.
import { BoxPlot } from "@synertech/ui";Props — BoxPlotProps
| Prop | Type | Default | Description |
|---|---|---|---|
data• |
ChartDatum[] |
— | One row per category compared. |
x• |
ChartXAxisConfig |
— | Field holding the name of each category. |
actions |
ReactNode |
— | Slot on the right of the caption: an export button, a range picker. A filter that frames several panels belongs in a |
boxSize |
number |
— | Caps the thickness of a box. |
color |
string |
— | Colour of the boxes. Defaults to the first palette slot. |
description |
ReactNode |
— | |
emptyState |
ReactNode |
— | Replaces the "no data" state: usually an |
error |
boolean |
false |
The data could not be loaded. Never the same thing as having none: a panel that says "no data" after a failed request states something false, and offers no way out. |
errorState |
ReactNode |
— | Replaces the whole built-in error state, message and button included. |
format |
(value: number) => string |
— | |
grid |
ChartGridLines |
"y" |
|
height |
number |
280 |
|
loading |
boolean |
false |
Dims the plot while fresh data loads; a first load shows a spinner. |
locale |
string |
— | BCP 47 tag the numbers and the dates are written in. Defaults to the |
margin |
Partial<ChartMargin> |
— | |
onBoxClick |
(box: BoxPlotBox) => void |
— | Called with the mark that was clicked. Enter and Space on the focused chart do the same for the mark the keyboard is on. |
onRetry |
() => void |
— | Draws the retry button in the error state, and is called when pressed. |
orientation |
CartesianOrientation |
"vertical" |
|
plotLabel |
string |
— | |
quantiles |
BoxPlotQuantileKeys |
— | Fields holding an already-computed summary, for the case where the raw observations never reach the browser. The whiskers then stop where the data says, and no outlier can be drawn: Tukey's fences need the observations, not their summary. |
referenceLines |
ChartReferenceLine[] |
— | |
showMean |
boolean |
false |
Marks the mean with a diamond, beside the median line. The distance between the two is the reading: a mean pulled away from the median is the shape of the tail, which is the whole reason this chart exists rather than a bar of averages. |
showOutliers |
boolean |
true |
Draws the observations beyond the whiskers. |
size |
ChartSize |
"md" |
|
tableView |
boolean | "toggle" |
false |
|
title |
ReactNode |
— | |
tooltip |
boolean | ((box: BoxPlotBox) => ReactNode) |
true |
|
values |
string |
— | Field holding the observations of a category, as an array of numbers. The chart then computes the quartiles, the whiskers and the outliers itself — which is the only way it can know what an outlier is. |
whisker |
number |
1.5 |
How many interquartile ranges the whiskers reach before a point counts as an outlier. Tukey's 1.5 by default. |
width |
number |
— | |
y |
ChartYAxisConfig |
— |
+ 276 inherited native attributes from HTMLAttributes, AriaAttributes, DOMAttributes (className, id, aria-*, event handlers…).
Types
BoxPlotBox
InterfaceOne box, as the tooltip and the click handler see it.
interface BoxPlotBox| Field | Type | Default | Description |
|---|---|---|---|
datum• |
ChartDatum |
— | |
index• |
number |
— | |
label• |
string |
— | |
mean• |
number | null |
— | Arithmetic mean. Only available when the raw observations were given. |
stats• |
BoxStats | null |
— |
|
x• |
ChartXValue |
— |
BoxPlotQuantileKeys
InterfaceFields holding an already-computed summary, when the observations are not at hand.
interface BoxPlotQuantileKeys| Field | Type | Default | Description |
|---|---|---|---|
median• |
string |
— | |
q1• |
string |
— | |
q3• |
string |
— | |
max |
string |
— | Upper whisker end. Defaults to |
min |
string |
— | Lower whisker end. Defaults to |