# Distribution Chart

Distribution chart for raw observations: histograms, box plot, violin, density, ridgeline, strip plot and error bars.

- Category: Charts
- Page: https://wunderui.com/components/distribution-chart
- Tier: Core and Pro

## Install

Distribution Chart ships with WunderUI Core and Pro in the @wunderui/react package.

## Import

```tsx
import { DistributionChart, DistributionChartProps, DistributionChartVariant } from "@wunderui/react"
```

## Minimal usage

Then use it:

```tsx
import { DistributionChart } from "@wunderui/react/charts"

const groups = [{ label: "API", values: [82, 91, 88, 120, 95, 140, 87, 99, 210, 101] }]

export function ResponseTime() {
  return <DistributionChart groups={groups} label="Response time" />
}
```

Expected result: You see a histogram of the ten response times, with most of them in the left bars and one slow value to the right.

## When to use

### Use Distribution Chart for

- How raw observations spread: latencies, durations, sizes
- Comparing the spread of two or three groups (boxplot, violin, ridgeline)
- Percentiles marked on a histogram

### Use something else

- [Bar Chart](https://wunderui.com/components/bar-chart) for values that are already summed per category
- [Range Bar Chart](https://wunderui.com/components/range-bar-chart) for a known minimum and maximum per category
- [Bubble Chart](https://wunderui.com/components/bubble-chart) for the relation between two measures
- [Heatmap](https://wunderui.com/components/heatmap) for values across two dimensions

## Keyboard

The plot is focusable: arrow keys walk the bins, or the groups on box, violin, strip and error-bar variants, and the live region reads each one.

| Key | Action |
|---|---|
| `Tab` or `Shift+Tab` | Moves focus to the plot and away from it. The plot is one tab stop; so is every legend badge. |
| `ArrowRight` or `ArrowLeft` | Moves to the next or previous bin. The tooltip follows, and a live region announces the one you are on. The first press starts at the first one (Left: the last one). |
| `Home` or `End` | Jumps to the first or last bin. |
| `Escape` | Clears the active point. |
| `Enter` or `Space` | On a legend badge of a ChartCard: switches its series off or on. The last visible series stays on. |

## Behavior

What the chart does on its own and what the page decides.

- **Raw values in:** Groups take a label, a colour and the raw numbers, not summaries. Bins, quartiles and densities are computed inside the chart, and the bin count sets the histogram resolution (24 by default).
- **Markers:** Markers draw labelled vertical lines at values such as p50 and p95, or a service-level target. A label that would touch its neighbour moves to the other side of its line or one row down, and none leaves the plot.
- **Box plot:** The box runs from Q1 to Q3 with the median inside. Whiskers reach 1.5 times the interquartile range, and points beyond are drawn as outlier dots.
- **Axis:** The count axis of histograms and densities starts at 0, the cumulative one runs 0 to 100 percent, and the other variants fit the axis to the data. Ridgeline drops the value axis.
- **Loading, empty and error:** Loading shows a shimmering skeleton, empty and error show a centred message, and error adds a Try again button when a retry handler is set. The card never changes height.
- **Legend:** A ChartCard shows the series as badges. With two or more, each badge toggles its series off (the last visible one stays on), and a static legend works for roles.
- **Size:** The chart fills the width of its container, and a height setting controls the plot. Text never scales, so labels keep their size at every width.

## Motion

The enter sequence and the hover follow the motion tokens of the library.

- **Enter:** Bins grow from the zero line, a box opens from its median, a violin widens from its axis and error bars open from the mean. Strip points pop in group by group, and outliers, caps and mean dots follow their shape.
- **Hover:** The hovered bin or group keeps its strength and the others dim.
- **Reduced motion:** With reduced motion the enter sequence is off and the chart appears at once. The tooltip, the crosshair and every state still work.

## Anatomy

- `DistributionChart`: Takes groups, each with a label, a colour and the raw numbers, not summaries. The bin count sets the histogram resolution (24 by default) and markers draw lines such as p50 and p95.
- `Plot`: The focusable region. Arrow keys walk the bins, or the groups on box, violin, strip and error-bar variants, and the live region reads each one.
- `Grid and axes`: The count axis of histograms and densities starts at 0, the cumulative one runs 0 to 100 percent, and the other variants fit the axis to the data. Ridgeline drops the value axis.
- `Shapes`: Bars for histograms, a box with whiskers and outlier dots for boxplot, a mirrored curve for violin, a smoothed line for density and ridgeline, and jittered dots for strip plot.
- `Markers`: Vertical reference lines with a label, for percentiles or a service-level target.
- `Tooltip`: The bin with its count, or on box variants the median, Q1 to Q3 and range, and on error bars the mean and one standard deviation.
- `Loading, empty and error`: Muted columns, or rows on ridgeline, under the shimmer; density loads as a muted area. Empty and error use the shared message and Try again button.
- `Data table and live region`: Bins or summary statistics as a table for screen readers.
- `Chart Markers`

## Best practices

### When to use

- Use DistributionChart to show spread, skew and outliers, for example response times or order values. Use BarChart when you already have one value per category.

### Do

- Pass the raw observations. Pre-aggregated bins break the quartiles and the density, because the chart aggregates once and the same way everywhere.
- Pick bins for the story. Around 20 to 30 shows the shape of a few thousand points, fewer than 10 hides it, and charts you compare should share one bin width.
- Mark the percentiles people act on, such as p50 and p95. A long tail looks harmless until a line shows where most requests end.

### Don't

- Don't use density or violin curves for fewer than about 30 points. The smoothing invents a shape, so show a strip plot of the points instead.
- Don't compare groups with histograms of different bin widths. Use a layered histogram or boxplot, which share one scale.

## API reference

### DistributionChart

| Prop | Type | Default | Description |
|---|---|---|---|
| groups* | readonly DistributionGroup[] |  | Raw observations per group (histogram variants use the first one or two). |
| activeIndex | number \| null |  | The active point (hovered or focused) as an index into `data`, to control it yourself. `null` shows none. |
| animate | boolean |  | Enter sequence (draw, wipe, grow) on scroll into view, after loading and on new data. Default true; off with reduced motion. |
| animationKey | string \| number |  | Change it to play the enter sequence again (e.g. `useChartReload().version`). New `data` replays it by itself. |
| aspectRatio | number |  | Width ÷ height when `height` is not set. Default 2.6. |
| axisFormatter | ChartValueFormatter |  | Value-axis labels; defaults to `valueFormatter`. |
| bins | number | 24 | Number of bins of the histogram variants (default 24). |
| categoryAxis | boolean |  | Category-axis labels (default true). |
| categoryFormatter | (label: string) => string |  | Shortens category labels on the axis, e.g. "Mar 12" → "Mar"; tooltip and pill keep the full label. |
| categoryTicks | readonly string[] |  | Only these category labels are shown on the axis (the rest stay hoverable). |
| className | string |  | Extra classes for the root element of the chart. |
| defaultActiveIndex | number \| null |  | The point that is active at first, for an uncontrolled chart. It shows the tooltip without a pointer. |
| defaultSelectedRange | ChartRange \| null |  | The range that is selected at first, for an uncontrolled chart. |
| description | string |  | Screen-reader summary; generated from the data when omitted. |
| emptyDescription | string |  | Text under the title in the empty state. |
| emptyTitle | string |  | Title of the message in the empty state. |
| errorDescription | string |  | Text under the title in the error state. |
| errorTitle | string |  | Title of the message in the error state. |
| grid | boolean |  | Grid lines (default true). |
| gridFade | boolean |  | The grid fades out towards both ends (default true). |
| gridIntervals | number |  | Number of equal grid intervals. Default: one per 44 px of plot height, capped by the size class (xs 2, sm 3, md 3, lg 4, xl 5). |
| gridStyle | "solid" \| "dashed" |  | Grid lines are dashed 4 / 4 by default; `solid` draws them through. |
| height | number |  | Fixed height of the plot frame in px. Without it the height follows the width (`aspectRatio`, `minHeight`, `maxHeight`): 220 px on a phone, up to 434 px (the plot of the Figma large card) from about 1130 px wide. |
| hiddenSeries | readonly string[] |  | Series keys that are switched off (legend toggle): drawn faded, dimmed in the tooltip. |
| includeZero | boolean |  | The value axis starts at 0 (owner rule, default). `false` fits the data (prices, temperatures). |
| label | string |  | Accessible name, e.g. the card title. |
| markers | readonly { value: number; label: string }[] |  | Vertical markers on the value axis, e.g. p50 / p95. |
| maxHeight | number |  | Highest height from `aspectRatio`. Default 434. |
| minHeight | number |  | Lowest height from `aspectRatio`. Default 220. |
| onActiveIndexChange | (index: number \| null) => void |  | Called with the index when the pointer or the arrow keys move to another point, and with `null` when they leave. Use it to show the hovered value in a headline. |
| onRetry | () => void |  | Shows a Try again button in the error state and calls this when it is pressed. |
| onSelectedRangeChange | (range: ChartRange \| null) => void |  | Called when a drag across the plot or Shift with an arrow key changes the range, and with `null` when Escape or a click clears it. |
| rangeSelectable | boolean |  | Allow selecting a range by dragging or Shift + arrow keys. On when `onSelectedRangeChange` is set. |
| resolution | "auto" \| "full" |  | `auto` (default): lines and areas draw at most 1.5 points per pixel (LTTB; hover and tooltip keep every point), and bars on a time axis that would get thinner than they may are gathered into weeks, months … `full` draws every point and eve… |
| selectedRange | ChartRange \| null |  | The selected range as inclusive indices `[from, to]` into `data`, to control it yourself. `null` selects nothing. |
| state | "ready" \| "loading" \| "empty" \| "error" |  | `loading` shows the chart-shaped skeleton, `empty` and `error` a message in the plot. |
| tooltip | boolean |  | Tooltip on hover / keyboard focus. Default true. |
| tooltipTitle | (datum: ChartDatum, index: number) => React.ReactNode |  | Title line of the tooltip; defaults to the category label. |
| valueAxis | boolean |  | Value-axis labels (default true). Off for compact cards and sparkline-like plots. |
| valueAxisPlacement | "auto" \| "outside" \| "inside" |  | Where the value labels go: `outside` left of the plot, `inside` in the plot above their grid lines (saves the label column on narrow charts). `auto` (default) puts them left of the plot at every size; `inside` is opt-in. |
| valueAxisSide | "left" \| "right" |  | Side of the value axis (vertical charts). `right` is the price axis of trading charts. |
| valueDomain | readonly [number, number] |  | Fix the value domain instead of fitting it to the data (still rounded to nice steps). |
| valueFormatter | ChartValueFormatter |  | Values in tooltip, labels, table and live region. Default: 42000 → "42k". |
| valueTicks | readonly number[] |  | Exact value-axis ticks (ascending), e.g. [0, 10000, … 70000]; replaces the nice-step domain. |
| variant | "histogram" \| "cumulative-histogram" \| "layered-histogram" \| "boxplot" \| "violin" \| "density" \| "ridgeline" \| "strip-plot" \| "error-bars" | "histogram" | Figma variant. Default `histogram`. |
| width | number |  | Fixed width instead of filling and measuring the container. |
| xScale | "band" \| "time" |  | `band` (default): the categories sit side by side in equal bands. `time`: the `index` field holds dates (Date, ms or a string such as "2026-03-01"); points sit at their real distance, the axis picks its tick level (hours → days → weeks → m… |

## Examples

### States

## In context

### Latency Percentiles

Histogram of API latency with p50 / p95 markers and the percentiles.

## For AI agents

`get_component("distribution-chart")`

Hand your agent this page as Markdown or the WunderUI MCP server, not a screenshot.
