Sparkline for React
A React sparkline is a tiny trend line for stat tiles and table cells, summarized in words for screen readers. Pass values as a readonly number[], oldest first.
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/sparkline.jsonRevenue
$34.2k▲ 18.6% vs last week
SparklinedefaultSparklineLabels
Sparklines in stat tiles
A small trend under a headline number.
Revenue
$12.4K
Sessions
86.4K
Bounce rate
38%
import { Sparkline } from "@/components/sheenui/charts/sparkline";
import { GlassCard } from "@/components/sheenui/glass-card/glass-card";
// Package build (after the first npm release, or a packed tarball): import { GlassCard, Sparkline } from "@sheenui/theme";
// This example also uses glass-card: npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/glass-card.json
const tiles: [string, string, number[], string][] = [
["Revenue", "$12.4K", [12, 18, 15, 22, 28, 26, 34], "rising"],
["Sessions", "86.4K", [40, 44, 39, 47, 52, 50, 58], "rising"],
["Bounce rate", "38%", [48, 46, 47, 43, 41, 40, 38], "falling"],
];
export function Example() {
return (
<>
{tiles.map(([label, value, values, direction]) => (
<GlassCard key={label} className="flex flex-col gap-2 p-5">
<p className="text-sm text-sheen-fg-muted">{label}</p>
<p className="text-3xl font-semibold tracking-tight">{value}</p>
<Sparkline values={values} aria-label={`${label} trend, ${direction}`} />
</GlassCard>
))}
</>
);
}Files to copy
5 folders · 12 files · 3 packages
- From
theme/src/ components/charts/{sparkline.tsx, chart-utils.ts}hooks/{use-controllable.ts, use-intersection.ts, use-latest.ts, use-media-query.ts, use-preferences.ts}motion/tokens.tslib/{cn.ts, form.ts, math.ts, warn-once.ts}styles/
- shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/sparkline.jsonRegistry item: sparkline. The styles need the Tailwind v4 glass UI setup.- The examples also use
components/glass-card/motion/light-follower.tslib/heading.ts
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/glass-card.json- Packages
pnpm add clsx motion tailwind-merge
Next.js: samples here pass functions (formatters, seriesLegend, a dashboard's load), so put them in a file that starts with "use client".
Sparkline props
SparklineLabels keys and English defaults (1)
When to use a sparkline
Use a React sparkline when there is no room for a full chart but the direction of a number matters: KPI tiles, table rows, list items. It answers one question, is this going up or down, at a glance.
Keep sparklines honest: use the same time range for every tile in a row, label the period near the number ("last 7 days"), and do not mix a rising line with a bad number without saying so in the label. Because the line has no axis, a sparkline can exaggerate small changes; the arrow and percent change next to the headline number give the scale.
Skip it when readers need exact values or a time axis: a sparkline has none and exaggerates small changes, so use a React line chart. Skip it for a single data point, and for series with fewer than about five points, where the number alone is clearer. For counts per bucket use the sparkbar, and for whole dashboards of tiles see the web analytics dashboard.
Frequently asked questions
All exports on this page
Sparkline— A tiny trend line for stat tiles.defaultSparklineLabels— The built-in English strings of Sparkline; spread it into your own labels and change what you need.
Keyboard
Accessibility
- The sparkline is an image with a name: write the direction into the aria-label ("Revenue trend, rising").
- It never carries information a sighted reader could not also get from the number beside it.
- Reduced motion: the line is drawn at once, without the draw-in.
Related pages
48 charts pages in all: browse them on Charts.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .