Combo Chart
Combine bars, lines and areas to compare related measures in one plot.
Use a combo chart when related measures read best as different marks, like actual values as bars against a target line, or when two measures need their own scales.
Installation
npx shadcn@latest add @kind-ui/combo-chartComposition
ComboChart
├── ComboChart.Background
├── ComboChart.Grid
├── ComboChart.XAxis
├── ComboChart.YAxis
├── ComboChart.Area
├── ComboChart.Bar
│ ├── ComboChart.Cell
│ └── ComboChart.Labels
├── ComboChart.Line
├── ComboChart.Scatter
├── ComboChart.Tooltip
├── ComboChart.Legend
└── ComboChart.ContentComboChart holds the data, the series config and the accessible name, and draws only the parts you add. Add one ComboChart.Area, ComboChart.Bar, ComboChart.Line or ComboChart.Scatter per measure. ComboChart.Cell colors a single bar and ComboChart.Labels writes values on a series. They share the x-axis, the tooltip and the legend, which read their labels, colors and value formats from config. ComboChart.Content places your own HTML next to the legend.
Usage
Series
Each series takes the same props as its own chart: ComboChart.Bar as in Bar Chart, ComboChart.Line as in Line Chart, and ComboChart.Area as in Area Chart. Series draw in the order you add them, so put areas first and lines last to keep the lines on top.
Set formatValue in config so the tooltip shows each measure in its unit.
Two Axes
When measures have different units, give each its own ComboChart.YAxis with a yAxisId, and point each series at its axis with the same yAxisId. Set orientation="right" on the second axis, and stackId on bars that add up:
Read each series against its own axis: equal heights don't mean equal values. Give each axis a tickFormatter with its unit so readers can tell them apart.
Percentage Stacks
Set stackOffset="expand" to show each stack as shares of 100%. Keep the raw values in data, and use createPercentStack to label the axis and tooltip as percentages:
import { ComboChart, createPercentStack } from "@kind-ui/charts";
const percent = createPercentStack({
values: (entry) => [entry.payload.online, entry.payload.store],
});
<ComboChart stackOffset="expand" {...props}>
<ComboChart.YAxis domain={[0, 1]} tickFormatter={percent.tickFormatter} />
<ComboChart.Bar dataKey="online" stackId="share" />
<ComboChart.Bar dataKey="store" stackId="share" />
<ComboChart.Tooltip normalizedValue={percent.normalizedValue} />
</ComboChart>values returns the raw values in the inspected entry's stack. If readers can hide series, return only the visible ones. For values that are already fractions, use formatPercent instead.
Legend and Keyboard
Pressing a legend item highlights its series and dims the others, and screen readers hear "Highlighted Retail." Press it again, or press Escape, to clear it. To hide and show series from the legend instead, see Legend.
Focus the chart and press the arrow keys to move between categories, which shows the tooltip with every measure, and Escape to dismiss it.
Motion
Series appear at once unless you set animate. Pass true and lines and areas draw in from left to right while bars grow from the axis. Pass options to change the shared direction and duration, and lineReveal, areaReveal or barReveal to override one type, or false to skip it:
<ComboChart
animate={{ revealDurationMs: 800, lineReveal: { revealDirection: "right-to-left" }, barReveal: false }}
{...props}
>When the reader prefers reduced motion, every series appears without animating. See Motion.
Loading
Set loading while the data is on its way. The chart keeps its size and shows a placeholder plot that sweeps across, or holds still when the reader prefers reduced motion. Screen readers hear loadingLabel ("Loading chart" by default). The legend and tooltip come back when loading turns off:
<ComboChart loading={isPending} loadingLabel="Loading production" {...props}>Background
Add ComboChart.Background for a decorative pattern behind the plot: pinpoints, crossings or waves. It adds nothing to the tooltip, legend or accessible name.
<ComboChart.Background pattern="pinpoints" opacity={0.15} />API Reference
ComboChart
Prop
Type
ComboAnimation
Prop
Type
ComboChart also takes every prop of Recharts' ComposedChart, like margin, layout and stackOffset. The series take the props listed on Bar Chart, Line Chart and Area Chart.