Searching Puzzle Pieces

Type to search Puzzle Pieces.

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.

Revenue
Target
Revenue, Target
monthRevenueTarget
Jan42k40k
Feb45k44k
Mar48k46k
Apr51k50k
May49k52k
Jun55k54k
Jul61k58k
Aug64k60k
Sep62k63k
Oct70k66k
Nov76k72k
Dec83k78k

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

Revenue
monthRevenue
Jan42k
Feb45k
Mar48k
Apr51k
May49k
Jun55k
Jul61k
Aug64k
Sep62k
Oct70k
Nov76k
Dec83k

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

Revenue
Target
Revenue, Target
monthRevenueTarget
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 figure with an aria-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-only table 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.