Sparkbar (Mini Bar Chart) for React
A React sparkbar is a mini bar chart for stat tiles and table cells, the bar twin of the sparkline. Pass values as a readonly number[], oldest first; a missing entry leaves a gap, never a zero.
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/sparkbar.jsonSignups, weekly
1,186▲ 12.7% vs last week
SparkbardefaultSparkbarLabels
In stat tiles
The latest bar is drawn at full strength; earlier bars recede to a lighter tint. Values below zero hang from a zero line. Use highlight="none" when no period is special.
Signups
1,284
Weekly, last 12 weeks
Orders
3,912
Daily, last 14 days
Net cash flow
+$18.4K
Weekly, US$ thousands
import { Sparkbar } from "@/components/sheenui/charts/sparkbar";
import { GlassCard } from "@/components/sheenui/glass-card/glass-card";
// Package build (after the first npm release, or a packed tarball): import { GlassCard, Sparkbar } 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 = [
{
label: "Signups",
value: "1,284",
values: [62, 74, 70, 81, 77, 92, 88, 97, 104, 99, 112, 126],
note: "Weekly, last 12 weeks",
},
{
label: "Orders",
value: "3,912",
values: [210, 244, 236, 251, 290, 302, 287, 276, 318, 331, 309, 358, 362, 371],
note: "Daily, last 14 days",
},
{
label: "Net cash flow",
value: "+$18.4K",
values: [4.2, -1.8, 3.1, 5.6, -0.6, -2.4, 1.9, 6.8, 3.3, -1.1, 4.7, 2.5],
note: "Weekly, US$ thousands",
highlight: "none" as const,
},
];
export function Example() {
return (
<>
{tiles.map((tile) => (
<GlassCard key={tile.label} className="flex min-w-0 flex-col gap-2 p-5">
<p className="text-sm text-sheen-fg-muted">{tile.label}</p>
<p className="text-3xl font-semibold tracking-tight">{tile.value}</p>
<Sparkbar
values={tile.values}
highlight={tile.highlight}
aria-label={`${tile.label}, ${tile.note.toLowerCase()}`}
/>
<p className="text-2xs text-sheen-fg-muted">{tile.note}</p>
</GlassCard>
))}
</>
);
}Files to copy
5 folders · 12 files · 3 packages
- From
theme/src/ components/charts/{sparkbar.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/sparkbar.jsonRegistry item: sparkbar. 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".
Win / loss in a table
Only the sign counts: up for a win, down for a loss, a short dash for a draw. Wins and losses use two distinct palette hues (not success and danger: a loss isn't an error).
| Team | Last 12 | W–D–L |
|---|---|---|
| Harbour City | 9–1–2 | |
| Northfield Rovers | 7–2–3 | |
| Ashdown Athletic | 5–2–5 | |
| Kestrel Town | 3–2–7 |
import { Sparkbar } from "@/components/sheenui/charts/sparkbar";
import { GlassCard } from "@/components/sheenui/glass-card/glass-card";
// Package build (after the first npm release, or a packed tarball): import { GlassCard, Sparkbar } from "@sheenui/theme";
// This example also uses glass-card: npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/glass-card.json
const standings = [
{ team: "Harbour City", results: [1, 1, -1, 1, 1, 0, 1, 1, -1, 1, 1, 1] },
{ team: "Northfield Rovers", results: [1, -1, 1, 0, 1, -1, 1, 1, 0, -1, 1, 1] },
{ team: "Ashdown Athletic", results: [-1, 1, 0, -1, 1, -1, -1, 1, 1, 0, -1, 1] },
{ team: "Kestrel Town", results: [-1, -1, 1, -1, 0, -1, 1, -1, -1, 1, -1, 0] },
];
export function Example() {
return (
<GlassCard className="overflow-hidden p-0">
<div role="region" aria-label="League form" tabIndex={0} className="overflow-x-auto">
<table className="w-full min-w-[30rem] text-start text-sm">
<caption className="sr-only">League form, last 12 matches</caption>
<thead className="text-xs text-sheen-fg-muted">
<tr className="border-b border-sheen-border">
<th scope="col" className="px-5 py-3 font-medium">Team</th>
<th scope="col" className="px-5 py-3 font-medium">Last 12</th>
<th scope="col" className="px-5 py-3 text-end font-medium">W–D–L</th>
</tr>
</thead>
<tbody>
{standings.map((row) => {
const w = row.results.filter((r) => r > 0).length;
const l = row.results.filter((r) => r < 0).length;
return (
<tr key={row.team} className="border-b border-sheen-border last:border-0">
<th scope="row" className="px-5 py-3 font-medium whitespace-nowrap">{row.team}</th>
<td className="w-56 px-5 py-3">
<Sparkbar
variant="winloss"
height={24}
values={row.results}
aria-label={`${row.team}, last 12 matches`}
/>
</td>
<td className="px-5 py-3 text-end whitespace-nowrap tabular-nums">
{w}–{row.results.length - w - l}–{l}
</td>
</tr>
);
})}
</tbody>
</table>
</div>
</GlassCard>
);
}Props
SparkbarLabels keys and English defaults (3)
Keyboard
Accessibility
- With an aria-label it is an image named by that label plus a short summary (or “No data”); without one it is decorative.
- Put the number it summarizes next to it as text: the bars are a glanceable hint, not the only source of the value.
- Under reduced motion nothing morphs: the bars render at their final values and new data replaces the old at once.
All exports on this page
Sparkbar— A tiny bar chart for stat tiles and table cells: magnitude ("bar") or wins and losses ("winloss").defaultSparkbarLabels— The built-in English strings of Sparkbar; spread it into your own labels and change what you need.
When to use the sparkbar chart
- Use it as a sparkline bar chart inside a stat tile to show the last twelve periods of a metric beside the current number, with the latest bar at full strength and history in a lighter tint.
- It fits a table cell showing a team's recent record, using variant winloss so only the sign of each result is drawn: up for a win, down for a loss, a short dash for a draw.
- It works for tiny trend hints in a list of accounts or projects, where hundreds of rows need a glanceable shape and not a full chart with axes.
- Skip it when readers need to hover for values or compare axes, since a sparkbar is not interactive; use BarChart for that, or Sparkline when the series is a continuous line rather than discrete periods.
- Pair it with Sparkline for continuous trends, Badge or a plain number for the headline value next to it, and DataTable to place a sparkbar in a column.
Frequently asked questions
Related pages
48 charts pages in all: browse them on Charts.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .