ComposedChart
Bars, lines and areas on one plot, with a second axis for a measure of another unit
Usage
ComposedChart is imported from its own subpath and needs the optional recharts peer.
npm install rechartsimport {ComposedChart} from "@peakui-pro/react/composed-chart";Anatomy
import {ComposedChart} from "@peakui-pro/react/composed-chart";
// Only the root is this package's own; the parts are the charting library's components under
// PeakUI names. The root is not exported from `@peakui-pro/react`, so an app that renders no
// chart never needs the peer installed, not even to render on a server.
export default () => (
<ComposedChart aria-label="Revenue and orders by month" data={[]}>
<ComposedChart.Grid />
<ComposedChart.XAxis />
<ComposedChart.YAxis yAxisId="left" />
<ComposedChart.YAxis orientation="right" yAxisId="right" />
<ComposedChart.Bar dataKey="revenue" yAxisId="left" />
<ComposedChart.Line dataKey="orders" yAxisId="right" />
<ComposedChart.Area dataKey="sessions" yAxisId="left" />
<ComposedChart.Tooltip content={<ComposedChart.TooltipContent />} />
</ComposedChart>
);Two axes
A measure in another unit (a rate beside a count) gets its own YAxis. Give each axis a yAxisId
and point every series at one with the same yAxisId; a series with no id uses the first axis.
Series order
Series are drawn in the order they are written, so a later series sits on top of an earlier one. Write the area first, then the bars, then the line, and the line stays readable over both.
Missing observations
A null field in data is a gap: a line or an area breaks at that category instead of falling to
zero. Set connectNulls on the series to draw across it.
Accessibility
The plot takes focus and answers the arrow keys, so aria-label names it, not the wrapper. Series
are told apart by colour; when two must still read without it, dash a line with strokeDasharray
(see Area With Line) and give every series a name the tooltip can print.
// Named by a string, or by the element that already carries the metric's title.
<ComposedChart aria-label="Revenue and orders by month" data={data} />
<ComposedChart aria-labelledby="revenue-title" data={data} />
// A chart that only repeats a figure printed beside it leaves the keyboard layer out.
<ComposedChart accessibilityLayer={false} data={data} />Examples
Stacked Bar With Line
One stackId across the bars stacks them; the line is a share of the column and sits on the
right-hand axis, fixed to domain={[0, 100]}.
Area With Line
An area carries the measure and a dashed line the target it is held against. The fill is a
gradient defined in the chart's <defs>.
Bar With Area
Multi Type
All three kinds on one plot: the area and the bars read the left axis, the line the right.
Customization
Tailwind CSS
<ComposedChart className="rounded-xl bg-surface p-4" data={data} />Global CSS
@layer components {
.chart {
--chart-axis-size: 11px;
--chart-grid-opacity: 0.4;
}
}Styling Reference
PeakUI follows the BEM methodology, so variants and states are plain class names you can target.
CSS Classes
The ComposedChart component uses these CSS classes (view source styles):
Base Classes
.chart- The block every cartesian chart carries; axis type, grid, tooltip cursor and dots.composed-chart- This chart's own block; gives the root its width
Slots
[data-slot="composed-chart"]- The root element
CSS Variables
| Variable | Purpose |
|---|---|
--chart-axis-size | Type size of the axis labels; set on .chart |
--chart-grid-opacity | How far the grid recedes behind the data; set on .chart |
--chart-1 … --chart-5 | The series ramp, derived from the theme's accent |
API Reference
ComposedChart
| Prop | Type | Default | Description |
|---|---|---|---|
data | Record<string, number | string | null>[] | - | Required. One object per category; a null field is a missing observation |
height | number | `${number}%` | 300 | Height of the plot |
width | number | `${number}%` | '100%' | Width of the plot |
margin | {top?: number; right?: number; bottom?: number; left?: number} | {top: 8, right: 8, bottom: 0, left: 0} | Space between the plot and the root's edges |
accessibilityLayer | boolean | true | Whether the plot is focusable and answers the arrow keys |
children | ReactNode | - | The chart's parts |
aria-label | string | - | Names the plot, which is what takes focus — not the wrapping <div> |
aria-labelledby | string | - | Names the plot by another element's id |
className | string | - | Additional classes |
...rest | ComponentProps<'div'> | - | Native <div> attributes, on the wrapper |
ComposedChart.Bar
The charting library's Bar, re-exported. See the Recharts Bar API.
ComposedChart.Line
The charting library's Line, re-exported. See the Recharts Line API.
ComposedChart.Area
The charting library's Area, re-exported. See the Recharts Area API.
ComposedChart.XAxis
The charting library's XAxis, re-exported. See the Recharts XAxis API.
ComposedChart.YAxis
The charting library's YAxis, re-exported. See the Recharts YAxis API.
ComposedChart.Grid
The charting library's CartesianGrid, re-exported. See the Recharts CartesianGrid API.
ComposedChart.Tooltip
The charting library's Tooltip, re-exported. See the Recharts Tooltip API.
ComposedChart.TooltipContent
ChartTooltip.Content, for the content prop of ComposedChart.Tooltip. Its props are on the ChartTooltip page.