Line Chart
A config-first, responsive multi-series line chart. A data array and a series schema render 2px lines against a hairline horizontal grid, with a nearest-x hover crosshair and tooltip. Series colors are assigned in fixed slot order; a legend appears automatically for two or more series.
| month | Revenue | Target |
|---|---|---|
| Jan | 42k | 40k |
| Feb | 45k | 44k |
| Mar | 48k | 46k |
| Apr | 51k | 50k |
| May | 49k | 52k |
| Jun | 55k | 54k |
| Jul | 61k | 58k |
| Aug | 64k | 60k |
| Sep | 62k | 63k |
| Oct | 70k | 66k |
| Nov | 76k | 72k |
| Dec | 83k | 78k |
Installation
Copy the piece and its math helper into your app — they compile with your build and the code is yours:
puzzle add piece line-chart
chart-math.js is a shared lib file — LineChart imports it as ../../lib/chart-math.js. It ships alongside the piece; keep it in app/lib/.
Usage
import LineChart from '@/components/ui/LineChart.pzl';
<LineChart data={ data } xKey="month" series={ series } />Single series
| month | Revenue |
|---|---|
| Jan | 42k |
| Feb | 45k |
| Mar | 48k |
| Apr | 51k |
| May | 49k |
| Jun | 55k |
| Jul | 61k |
| Aug | 64k |
| Sep | 62k |
| Oct | 70k |
| Nov | 76k |
| Dec | 83k |
One series gets no legend — there is only one color, so the surrounding title already says what is plotted. The rule holds even if you pass showLegend explicitly.
Custom height and value formatting
| month | Revenue | Target |
|---|---|---|
| Jan | $42,000 | $40,000 |
| Feb | $45,000 | $44,000 |
| Mar | $48,000 | $46,000 |
| Apr | $51,000 | $50,000 |
| May | $49,000 | $52,000 |
| Jun | $55,000 | $54,000 |
| Jul | $61,000 | $58,000 |
| Aug | $64,000 | $60,000 |
| Sep | $62,000 | $63,000 |
| Oct | $70,000 | $66,000 |
| Nov | $76,000 | $72,000 |
| Dec | $83,000 | $78,000 |
Accessibility
The hover crosshair and tooltip are a progressive enhancement — every value they reveal is also reachable without a pointer. The chart is built so assistive tech never depends on the drawing:
- The root is a
figurewith anaria-label(the label prop, or the series labels joined), so the whole chart announces as one named figure. - The SVG itself is
aria-hidden— the marks carry no semantics a screen reader could use. - A visually-hidden
sr-onlytable twins the plot: x values are row headers and each series is a column, so the exact numbers are read in order without ever hovering.