Charts
BarChart
Compare values across categories. Several series are drawn side by side or stacked; negative values extend below the zero line.
import '@reactloom/charts/styles.css';
import { BarChart } from '@reactloom/charts';Examples
Grouped
- Web
- Mobile
- Partner
import { BarChart } from '@reactloom/charts';
import { quarterly } from './data';
export default function Example() {
return (
<BarChart
title="Sign-ups by channel and quarter"
data={quarterly}
x="quarter"
yLabel="Sign-ups"
series={[
{ key: 'web', label: 'Web' },
{ key: 'mobile', label: 'Mobile' },
{ key: 'partner', label: 'Partner' },
]}
/>
);
}Stacked
The top of each bar is the quarter’s total.
- Web
- Mobile
- Partner
import { BarChart } from '@reactloom/charts';
import { quarterly } from './data';
export default function Example() {
return (
<BarChart
title="Total sign-ups per quarter"
data={quarterly}
x="quarter"
stacked
series={[
{ key: 'web', label: 'Web' },
{ key: 'mobile', label: 'Mobile' },
{ key: 'partner', label: 'Partner' },
]}
/>
);
}Negative values and currency
import { BarChart } from '@reactloom/charts';
const cashFlow = [
{ month: 'Jul', net: 18400 },
{ month: 'Aug', net: 9200 },
{ month: 'Sep', net: -6300 },
{ month: 'Oct', net: -2100 },
{ month: 'Nov', net: 12800 },
{ month: 'Dec', net: 21500 },
];
export default function Example() {
return (
<BarChart
title="Net cash flow, second half"
description="Two negative months after the September hiring round; positive again from November."
data={cashFlow}
x="month"
series={[{ key: 'net', label: 'Net cash flow' }]}
valueFormat={{ style: 'currency', currency: 'EUR', maximumFractionDigits: 0 }}
height={240}
/>
);
}API reference
| Prop | Type | Default |
|---|---|---|
titlerequired | string | — |
datarequired | Row[] | — |
xrequiredThe category of each bar. | key | (row) => string | — |
seriesrequired | { key, label, value?, color? }[] | — |
stackedOne bar per category with series stacked. | boolean | — |
descriptionGenerated when omitted. | ReactNode | — |
valueFormat · formatValueAs LineChart. | | — |
xLabel · yLabel | string | — |
yDomainThe axis always includes zero. | [min, max] | — |
table | 'toggle' | 'visible' | 'none' | 'toggle' |
height | number | 280 |
Customization
Series colours are the theme tokens --pl-color-chart-1 to --pl-color-chart-6, used in order. Set them in a theme (createTheme({ colors: { 'chart-1': '#0E7C66' } }), contrast-checked by checkThemeContrast) or per series with color.
Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.
Renders CartesianChart, so its hooks apply too.
State attributes
Target these in your CSS to style states without depending on class names.
| Attribute | Values |
|---|---|
[data-series] | present when on |
[data-zero] | present when on |
Theme tokens it reads
--pl-color-bg-subtle --pl-color-bg-surface --pl-color-border-default --pl-color-border-strong --pl-color-border-subtle --pl-color-fg-muted --pl-color-fg-subtle --pl-focus-ring-color --pl-focus-ring-offset --pl-focus-ring-width --pl-font-size-sm --pl-font-size-xs --pl-radius-md --pl-radius-sm --pl-radius-xs
Accessibility
- Each chart is a
<figure>named by its title and described by a summary. Write thedescriptionyourself to state the takeaway; otherwise a factual summary is generated from the data (range, lowest and highest values, change from first to last), formatted for the active locale. - The drawing is hidden from assistive technology. Screen-reader users get the summary and the data table (“Show data table”), which is a real, sortable table.
- The plot is one tab stop. Arrow keys move between data points, a visible tooltip follows, and a polite live region reads the values. It is not
role="application", so screen readers keep their normal reading keys; in browse mode, use the table. - Colours come from the theme’s chart palette, each at least 3:1 against the background in every built-in theme. In Windows high-contrast mode series switch to system colours with dash patterns.
- In right-to-left layouts the x axis runs from the right and the value axis moves to the right side; ← moves forward.
| Key | Action |
|---|---|
| Tab | Focus the plot |
| → / ↓ | Next category (← in right-to-left layouts) |
| ← / ↑ | Previous category |
| Home / End | First / last category |
| Escape | Hide the tooltip |
Usage guidelines
Do
- Sort categories by value when their order does not matter.
- Start bars at zero (BarChart always does).
Don’t
- Don’t use more than about four series side by side; stack them or split the chart.