Bar Chart
A config-first categorical bar chart. Hand it row objects, an xKey, and a series list — it renders responsive SVG bars with a legend, per-bar hover tooltips, and an accessible data table. One series draws a plain bar chart; multiple series render grouped, or stacked with stacked.
| month | Sales |
|---|---|
| Jan | 4.2k |
| Feb | 5.1k |
| Mar | 4.8k |
| Apr | 6.3k |
| May | 7.1k |
| Jun | 6.8k |
| Jul | 8.2k |
| Aug | 7.6k |
Installation
Copy the piece and its math helper into your app — they compile with your build and the code is yours:
puzzle add piece bar-chart
Bars are true SVG paths with 4px-rounded tops and a flat baseline; colors are assigned in fixed slot order (first series → chart-1). The chart is presentational — own the data in the parent and feed it in. Requires the pieces.css tokens merged into your app styles (see Introduction).
Usage
import BarChart from '@/components/ui/BarChart.pzl';
<BarChart data={ salesData } xKey="month" series={ [{ key: 'sales', label: 'Sales' }] } label="Monthly sales" />Grouped
| quarter | 2026 | 2025 |
|---|---|---|
| Q1 | 3.2k | 2.4k |
| Q2 | 4.1k | 3.3k |
| Q3 | 3.8k | 4k |
| Q4 | 5.2k | 4.3k |
Stacked
| month | Product | Services | Other |
|---|---|---|---|
| Jan | 3.2k | 1.8k | 900 |
| Feb | 3.6k | 2.1k | 1.1k |
| Mar | 4.1k | 2.4k | 1k |
| Apr | 4.8k | 2.6k | 1.3k |
| May | 5.2k | 3k | 1.5k |
Accessibility
The root is a <figure> with an aria-label from the label prop, and the decorative SVG is marked aria-hidden="true". Every value is also emitted as a visually hidden <table> after the plot, so the data is reachable by screen readers and never gated behind a hover tooltip. Colors carry series identity, but the legend and table carry it too — nothing depends on color alone.
Always pass a descriptive label — it names both the figure and the data table.