Examples

Grouped

Preview
Sign-ups by channel and quarterGrouped bar chart of Web, Mobile, and Partner, 4 points from Q1 to Q4. Web: lowest 1,240 (Q1), highest 1,610 (Q4). Up 29.8% from first to last. Mobile: lowest 860 (Q1), highest 1,320 (Q4). Up 53.5% from first to last. Partner: lowest 310 (Q1), highest 480 (Q4). Up 54.8% from first to last.
  • Web
  • Mobile
  • Partner
Use the arrow keys to move between data points, Home and End to jump to the first and last.
Example.tsx
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.

Preview
Total sign-ups per quarterStacked bar chart of Web, Mobile, and Partner, 4 points from Q1 to Q4. Web: lowest 1,240 (Q1), highest 1,610 (Q4). Up 29.8% from first to last. Mobile: lowest 860 (Q1), highest 1,320 (Q4). Up 53.5% from first to last. Partner: lowest 310 (Q1), highest 480 (Q4). Up 54.8% from first to last.
  • Web
  • Mobile
  • Partner
Use the arrow keys to move between data points, Home and End to jump to the first and last.
Example.tsx
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

Preview
Net cash flow, second halfTwo negative months after the September hiring round; positive again from November.
Use the arrow keys to move between data points, Home and End to jump to the first and last.
Example.tsx
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

BarChart props
PropTypeDefault
titlerequired
string—
datarequired
Row[]—
xrequired
The category of each bar.
key | (row) => string—
seriesrequired
{ key, label, value?, color? }[]—
stacked
One bar per category with series stacked.
boolean—
description
Generated when omitted.
ReactNode—
valueFormat · formatValue
As LineChart.
—
xLabel · yLabel
string—
yDomain
The axis always includes zero.
[min, max]—
table
'toggle' | 'visible' | 'none''toggle'
height
number280

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.

AttributeValues
[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 the description yourself 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.
Keyboard interactions
KeyAction
TabFocus the plot
→ / ↓Next category (← in right-to-left layouts)
← / ↑Previous category
Home / EndFirst / last category
EscapeHide 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.