Searching Puzzle Pieces

Type to search Puzzle Pieces.

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.

Monthly sales
monthSales
Jan4.2k
Feb5.1k
Mar4.8k
Apr6.3k
May7.1k
Jun6.8k
Jul8.2k
Aug7.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

2026
2025
Revenue by quarter, year over year
quarter20262025
Q13.2k2.4k
Q24.1k3.3k
Q33.8k4k
Q45.2k4.3k

Stacked

Product
Services
Other
Revenue by segment
monthProductServicesOther
Jan3.2k1.8k900
Feb3.6k2.1k1.1k
Mar4.1k2.4k1k
Apr4.8k2.6k1.3k
May5.2k3k1.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.