Charts

LineChart, BarChart, DonutChart and Sparkline — hand-rolled SVG on d3-scale/d3-shape, animated.

srui's charts are hand-rolled SVG built on d3-scale/d3-shape (standing decision: full control over preset styling and animation). Line paths draw themselves in via the pathLength={1} trick; bars grow from their own baseline with transform-box: fill-box; the donut sweeps its stroke-dashoffset like the line chart.

Installation

import { LineChart, BarChart, DonutChart, Sparkline } from "@iammikz/srui";

LineChart

020406080JanFebMarAprMayJunJul
RevenueSignups

LineChart props

PropTypeDefaultDescription
labelsstring[]—X-axis category labels
seriesLineChartSeries[] ({ name, values, color? })—One stroked path each
heightnumber240Plot height in px (viewBox width is 600)
areabooleanfalseFill under the line with 15% opacity
tooltipbooleantrueHover/keyboard tooltip — guide line + value bubble at the nearest point
showGrid / showLegendbooleantrueToggle gridlines / legend
classNamestring—For the wrapping figure

Series colors default to var(--chart-1) … var(--chart-8).

Tooltips: hover (or focus + arrow keys) any point to get a guide line with dots and a bubble listing every series' value — the interactive layer srui charts were missing, on the same hand-rolled SVG (no recharts dependency). BarChart highlights the hovered bar group the same way.

Area mode

020406080JanFebMarAprMayJunJul

BarChart

010203040JanFebMarAprMayJunJul
20242025

BarChart props

Same shape as LineChart minus area: labels, series, height, showGrid, showLegend, className. Multiple series render grouped bars; bars animate in with a per-bar stagger.

DonutChart

A ring/gauge whose arc sweep animates like the line draw-in. Use it for part-to-whole values (a single slice) or progress.

68%
Storage

DonutChart props

PropTypeDefaultDescription
labelstring—Text under the value
valuenumber—0–100 portion of the ring
suffixstring""Rendered after the value
sizenumber160SVG size in px
colorstringvar(--chart-2)Arc color

Sparkline

A minimal LineChart variant — no axes, gridlines or legend — sized for inline use in a table cell or a StatCard-style tile.

Weekly signups
1,284

Sparkline props

PropTypeDefaultDescription
valuesnumber[]—The series
width / heightnumber120 / 36SVG dimensions
colorstringvar(--chart-1)Stroke color
strokeWidthnumber2Stroke weight

Accessibility

Each chart SVG carries role="img" and an aria-label describing the series ("Line chart: Revenue" / "Line chart with 2 series"); legends are figcaptions. For data-critical contexts, provide the underlying numbers in a table or sr-only text — charts are decorative summaries by default.

All draw/grow animations are motion-safe:-gated with final states baked into the markup, so reduced-motion users always see complete charts (see the pathLength={1} gotcha in the plan).