Combo chart
Amounts as bars with one or two lines over the same categories: orders against a target, sales against conversion. There is one value axis. A line on another scale is drawn indexed, as a percent of its own peak, so its shape can be compared with the bars while its real values stay in the readout. For several lines alone, use the line chart.
Install
npx shadcn@latest add @thrum-pro/combo-chartThis is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.
Data shape
type ComboChartSeries = {
key: string;
name: string;
values: (number | null)[]; // one per label
color?: string;
};
type ComboChartLine = ComboChartSeries & {
indexed?: boolean;
format?: Intl.NumberFormatOptions;
};bars: [{ key: "orders", name: "Orders", values: [1240, 1310, 1185] }],
lines: [{ key: "rate", name: "Conversion", indexed: true,
values: [0.031, 0.034, 0.029], format: { style: "percent" } }]Props
| Prop | Type | Default | Description |
|---|---|---|---|
labels | readonly string[] | Required | Names of the categories on the horizontal axis, in order. |
bars | readonly ComboChartSeries[] | Required | One to three bar series, drawn side by side in each category, from zero. A fourth and later are left out. |
lines | readonly ComboChartLine[] | Default [] | Up to two lines through the middle of each category. A line drawn on the shared axis must measure the same thing as the bars. With indexed: true, the line is drawn as a percent of its own largest value, scaled so that peak sits level with the highest bar or line on the axis; the axis does not read its values, the readout and the table do. |
label | string | Required | What the chart measures. Read by screen readers and used as the table caption. |
format | Intl.NumberFormatOptions | Default compact | How values are written on the axis, in the readout and in the data table. A line's own format wins for that line. |
locale | string | Default "en-US" | Locale for number formatting. Fixed by default so the server and the browser print the same text. |
yAxis | boolean | Default true | Show value lines and their labels. The axis always includes zero. |
xAxis | boolean | Default true | Show category labels along the bottom. Every nth one is shown so the widest has room. |
legend | boolean | Default true | Show a swatch and a name for each series: a square for bars, a short line for lines, and “(indexed)” after an indexed line. It appears when there are two or more series. |
onActiveChange | (index: number | null) => void | – | Called with the index of the category under the cursor, or null when the cursor leaves. |
sound | boolean | Default true | Play a tick as the cursor moves between categories, if the visitor has sound on. |
emptyLabel | string | Default "No data" | Text shown when no series has a value. |
className | string | – | Sets the size. The default is full width and 288 pixels tall, legend included. |
Motion and sound
Motion
- First draw: each group of bars grows from the zero line in 250 ms, 40 ms apart, while the lines are revealed left to right in 700 ms at constant speed.
- New data with the same number of categories: bars and lines move to their new values in 400 ms with no overshoot. A different number switches at once.
- The band behind the active category and the dots on the lines follow the pointer on a stiff spring.
- Reduced motion: the chart appears complete, and data changes and the cursor move instantly.
Sound
- A soft tick each time the cursor lands on a different category, at most one every 40 ms.
Sound is off until the visitor turns it on. Pass sound={false} to keep this component silent. How sound works
Accessibility
- The chart is one tab stop. It is exposed as a slider whose value text lists every series at the cursor, for example “Mar: Orders 1.2K, Target 1.3K, Conversion 2.9% (81% of its peak)”.
- A visually hidden table carries every value of every series, lines in their own format.
- Bars and lines are told apart by shape in the legend and the readout, not only by colour. Lines carry a ring of background where they cross a bar.
- The whole plot is the pointer target, so a reader never has to hit a 2 pixel line.
| Keys | Action |
|---|---|
| Tab | Focus the chart. The cursor goes to the last category. |
| ← → | Move the cursor one category. |
| Home / End | Jump to the first or last category. |
| Esc | Hide the cursor. |
Source
The source comes with Pro
TypeScript source · Copy-paste ready · MIT-compatible for client projects · Includes all dependencies
Files and dependencies
- Adds
components/ui/combo-chart.tsx- Packages
motion- Brings along
- Chart foundationsMotion tokensSound engine
Changelog
- 1.0.0 · 2026-12-03First release.