Line Chart
A line chart recipe - Recharts drawn with Appica UI tokens, for comparing trends over time.
A line chart compares how 1 or more measures move over time. Like every chart here it is a recipe: Recharts draws it and the chart layer themes it. Each example below is a complete file to paste and adapt.
Installation
Recharts is the only extra dependency, with react-is at the same version as react:
pnpm add recharts react-isThe examples import the chart layer from @/components/chart. If your project doesn't have it yet, copy it from the Charts page first.
Examples
Default
A 2 px line with no dots at rest, and Sparkline's indicator on the hovered point. The dates on the axis and in the tooltip go through Intl.DateTimeFormat, and minTickGap drops the ticks that would crowd.
Multiple
Each series takes the next color of chartColors as its stroke, in order. With 2 or more lines the chart needs a Legend.
Dots
For a few points far apart, such as quarters, show them: a dot filled with the surface color and straight segments (type="linear"), so nothing is implied between 2 measurements.
Reference line
A target or a baseline is a ReferenceLine. The theme draws it in --foreground-subtle, the neutral color, and a dash sets it apart from the data.
Interactive
Give the Legend an onClick and ChartLegend renders each item as a toggle button. The state lives in your component: pass it to each line as hide, and Recharts rescales the axis to the lines that remain.
Accessibility
- Pass
aria-labelto the chart with what it shows ("Orders per day over 2 weeks"). It becomes the accessible name of the SVG. - The chart takes focus, and the left and right arrow keys move the tooltip from point to point.
- A chart with 2 or more lines has a
Legend, and the tooltip names every series, so color is never the only cue. - A legend item that toggles a line is a real
<button>witharia-pressed, reachable with Tab and operable with Enter or Space. - Nothing animates under reduced motion.