Animated React Charts
Animated React charts with tooltips, keyboard reading and a table view for every one.
Files to copy
14 folders · 22 files · 4 packages
- From
theme/src/ components/charts/components/button/components/drawer/parts/sheet.tsxcomponents/kbd/components/menu/components/number-ticker/components/segmented/components/skeleton/components/spinner/components/status-icons/hooks/{use-controllable.ts, use-direction.ts, use-intersection.ts, use-latest.ts, use-magnetic.ts, use-media-query.ts, use-preferences.ts, use-resolved-scheme.ts}motion/{gate.ts, tokens.ts}lib/{canvas-effects.ts, cn.ts, csv.ts, form.ts, glide-highlight.tsx, heading.ts, math.ts, popup-a11y.ts, popup-motion.ts, state-light.tsx, warn-once.ts}styles/
- shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/bar-chart.jsonRegistry items: bar-chart, bar-list, beeswarm, box-plot, bullet-chart, bump-chart, candlestick-chart, chart-table-twins, chord-diagram, cohort-chart, combo-chart, diverging-bar-chart, dumbbell-chart, error-bar-chart, funnel-chart, gantt-chart, gauge-chart, geo-map, line-chart, lollipop-chart, marimekko-chart, network-graph, pie-chart, polar-area-chart, population-pyramid, radar-chart, radial-bar-chart, radial-progress, ridgeline-chart, sankey-chart, scatter-chart, sparkbar, sparkline, stacked-area-chart, step-line-chart, streaming-chart, sunburst-chart, tracker-chart, treemap, waffle-chart, waterfall-chart. The command installs the first; swap the name in the URL for any other. The styles need the Tailwind v4 glass UI setup.- The examples also use
components/glass-card/motion/light-follower.ts
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json https://lokendra-builds.github.io/sheenui/r/donut-chart.json https://lokendra-builds.github.io/sheenui/r/glass-card.json https://lokendra-builds.github.io/sheenui/r/line-chart.json https://lokendra-builds.github.io/sheenui/r/radial-progress.json https://lokendra-builds.github.io/sheenui/r/sparkline.json- Packages
pnpm add @base-ui/react 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".
Every chart, live
52 live previews of the 48 chart components: some charts appear more than once, as variants. Each one is the real component with its own data, loaded as you scroll. Open one for its docs, props and keyboard map.
Showing 12 of 52 chart previews
Featured
One store, four charts, moving together
Hover or arrow-key through any chart and the others follow. Drag the brush to zoom all of them, click a legend key to hide a series, and every number re-counts for the days you picked.
Revenue, 42 days
$513.7K +27.4% versus the previous period
Orders
11,004 +32.3% versus the previous period
Average order
$47 −3.7% versus the previous period
Conversion
2.6%
Revenue by channel
Aug 21 – Oct 1, daily, US dollars
- Organic
- Paid
- Previous period
Orders
- Orders
- Previous period
Conversion rate
Channel mix
Share of revenue
Visitors right now
A new reading every 2 s; pauses off-screen and in hidden tabs.
934on the site
About charts
Frequently asked questions
Line, area, bar and donut
The everyday charts, documented here. Smooth curves, gradient fills, draw-in and grow-from-baseline entrances, previous-period comparison, clickable legends, annotations, a brush, synced crosshairs and PNG / SVG / CSV export. As a shadcn charts alternative, each chart has a table view.
Line chart
Click a legend key to hide a series (the axis re-fits); hover one to dim the others. The dashed line is the previous period. Download it from the card's menu.
Monthly revenue by channel
In US dollars, with last year dashed
- Organic
- Paid
- Referral
- Previous period
import { ChartCard } from "@/components/sheenui/charts/chart-parts/chart-card";
import { ChartTable } from "@/components/sheenui/charts/chart-parts/empty-table";
import { seriesLegend } from "@/components/sheenui/charts/chart-parts/legend-tooltip";
import { formatCompact, type CompareSeries } from "@/components/sheenui/charts/chart-utils";
import { LineChart, PREVIOUS_SERIES_KEY } from "@/components/sheenui/charts/line-chart";
// Package build (after the first npm release, or a packed tarball): import { ChartCard, ChartTable, LineChart, PREVIOUS_SERIES_KEY, formatCompact, seriesLegend, type CompareSeries } from "@sheenui/theme";
const usd = (n: number) => "$" + formatCompact(n);
const data = [
{ month: "Jan", organic: 61000, organicPrev: 52000, paid: 34000, referral: 15000 },
{ month: "Feb", organic: 64500, organicPrev: 54500, paid: 36500, referral: 15800 },
{ month: "Mar", organic: 69000, organicPrev: 56000, paid: 38200, referral: 17100 },
{ month: "Apr", organic: 72800, organicPrev: 59500, paid: 41000, referral: 17600 },
{ month: "May", organic: 78100, organicPrev: 61000, paid: 43600, referral: 18900 },
{ month: "Jun", organic: 83400, organicPrev: 63800, paid: 45200, referral: 19700 },
];
// color is a palette slot (1–8); compareKey names the previous-period value in each row.
const series: CompareSeries[] = [
{ key: "organic", label: "Organic", color: 1, compareKey: "organicPrev" },
{ key: "paid", label: "Paid", color: 2 },
{ key: "referral", label: "Referral", color: 3 },
];
export function Example() {
return (
<ChartCard
title="Monthly revenue by channel"
legend={[
...seriesLegend(series, "line"),
{ label: "Previous period", color: "var(--sheen-fg-subtle)", kind: "line", dashed: true, key: PREVIOUS_SERIES_KEY },
]}
exportable
table={<ChartTable data={data} index="month" series={series} format={usd} />}
>
<LineChart data={data} index="month" series={series} format={usd} aria-label="Monthly revenue by channel" />
</ChartCard>
);
}Area chart with a brush
A gradient wash that fades to transparent. The brush under a long series zooms it: drag the window, drag its edges, or use the arrow keys on them.
Visits
Daily, last 120 days
import { ChartCard } from "@/components/sheenui/charts/chart-parts/chart-card";
import { ChartTable } from "@/components/sheenui/charts/chart-parts/empty-table";
import { type ChartSeries } from "@/components/sheenui/charts/chart-utils";
import { AreaChart } from "@/components/sheenui/charts/line-chart";
// Package build (after the first npm release, or a packed tarball): import { ChartCard, ChartTable, AreaChart, type ChartSeries } from "@sheenui/theme";
// 120 days of visits
const days = Array.from({ length: 120 }, (_, i) => ({
day: "Day " + (i + 1),
visits: Math.round(9000 + i * 55 + Math.sin(i / 4) * 900),
}));
const series: ChartSeries[] = [{ key: "visits", label: "Visits", color: 7 }];
export function Example() {
return (
<ChartCard title="Visits" table={<ChartTable data={days} index="day" series={series} />}>
<AreaChart
data={days}
index="day"
series={series}
brush={{ defaultRange: [90, 119], minSpan: 7 }}
aria-label="Daily visits"
/>
</ChartCard>
);
}Bar chart
Bars grow from the baseline. The dashed tick on each Signups bar is last year's value.
Signups vs activations
- Signups
- Activated
- Signups, previous period
import { BarChart } from "@/components/sheenui/charts/bar-chart";
import { type CompareSeries } from "@/components/sheenui/charts/chart-utils";
// Package build (after the first npm release, or a packed tarball): import { BarChart, type CompareSeries } from "@sheenui/theme";
const data = [
{ month: "Jan", signups: 1240, signupsPrev: 1010, activated: 780 },
{ month: "Feb", signups: 1310, signupsPrev: 1090, activated: 820 },
{ month: "Mar", signups: 1490, signupsPrev: 1150, activated: 930 },
{ month: "Apr", signups: 1420, signupsPrev: 1230, activated: 900 },
{ month: "May", signups: 1650, signupsPrev: 1300, activated: 1040 },
];
const series: CompareSeries[] = [
{ key: "signups", label: "Signups", color: 1, compareKey: "signupsPrev" },
{ key: "activated", label: "Activated", color: 3 },
];
export function Example() {
return <BarChart data={data} index="month" series={series} aria-label="Signups and activations per month" />;
}Stacked bars
import { BarChart } from "@/components/sheenui/charts/bar-chart";
import { type ChartSeries } from "@/components/sheenui/charts/chart-utils";
// Package build (after the first npm release, or a packed tarball): import { BarChart, type ChartSeries } from "@sheenui/theme";
const data = [
{ month: "Jan", free: 820, pro: 310, team: 90 },
{ month: "Feb", free: 790, pro: 358, team: 111 },
{ month: "Mar", free: 760, pro: 406, team: 132 },
{ month: "Apr", free: 730, pro: 454, team: 153 },
];
const series: ChartSeries[] = [
{ key: "free", label: "Free", color: 7 },
{ key: "pro", label: "Pro", color: 1 },
{ key: "team", label: "Team", color: 3 },
];
export function Example() {
return <BarChart stacked data={data} index="month" series={series} aria-label="Customers per plan" />;
}Horizontal bars
Best for long category names. Values sit at the tip of each bar.
import { BarChart } from "@/components/sheenui/charts/bar-chart";
// Package build (after the first npm release, or a packed tarball): import { BarChart } from "@sheenui/theme";
const countries = [
{ country: "United States", visitors: 48200 },
{ country: "Germany", visitors: 21400 },
{ country: "India", visitors: 18900 },
{ country: "United Kingdom", visitors: 15300 },
{ country: "Brazil", visitors: 9800 },
];
export function Example() {
return (
<BarChart
layout="horizontal"
showValues
data={countries}
index="country"
series={[{ key: "visitors", label: "Visitors" }]}
aria-label="Visitors by country"
/>
);
}Donut chart
Part-to-whole at a glance, at most 6 slices. Hover a slice to read it in the center; click a legend key to leave a slice out (the ring re-flows and the total re-counts).
import { ChartCard } from "@/components/sheenui/charts/chart-parts/chart-card";
import { ChartTable } from "@/components/sheenui/charts/chart-parts/empty-table";
import { DonutChart } from "@/components/sheenui/charts/donut-chart";
// Package build (after the first npm release, or a packed tarball): import { ChartCard, ChartTable, DonutChart } from "@sheenui/theme";
const traffic = [
{ label: "Organic search", value: 41200 },
{ label: "Direct", value: 22800 },
{ label: "Social", value: 15400 },
{ label: "Referral", value: 9600 },
{ label: "Email", value: 6100 },
];
export function Example() {
return (
<ChartCard
title="Traffic sources"
description="Sessions this month"
table={
<ChartTable
data={traffic.map((t) => ({ source: t.label, sessions: t.value }))}
index="source"
indexLabel="Source"
series={[{ key: "sessions", label: "Sessions", color: 1 }]}
/>
}
>
<DonutChart data={traffic} labels={{ center: "Sessions" }} aria-label="Sessions by traffic source" />
</ChartCard>
);
}Radial progress & gauge
A single ratio against a limit; the number rolls with the arc. With coloring="severity" the color turns warning and critical, always with a status word too.
import { RadialProgress } from "@/components/sheenui/charts/radial-progress";
// Package build (after the first npm release, or a packed tarball): import { RadialProgress } from "@sheenui/theme";
export function Example() {
return (
<>
<RadialProgress value={64} label="Quarterly goal" />
<RadialProgress variant="gauge" coloring="severity" value={82} label="Storage used" />
<RadialProgress variant="gauge" coloring="severity" value={96} label="CPU" />
</>
);
}Sparklines in stat tiles
A small trend under a headline number; it draws in when the tile scrolls into view and the latest point gets a dot.
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";
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>
))}
</>
);
}Chart-wide features
The same building blocks power every chart above and the dashboards: synced crosshairs, annotations, export, live data and i18n.
Synced crosshairs
Charts inside one ChartSyncProvider share the point being read, matched by x value: hover the line and the bars follow (and the other way round).
import { BarChart } from "@/components/sheenui/charts/bar-chart";
import { ChartSyncProvider } from "@/components/sheenui/charts/chart-sync";
import { type ChartSeries } from "@/components/sheenui/charts/chart-utils";
import { LineChart } from "@/components/sheenui/charts/line-chart";
// Package build (after the first npm release, or a packed tarball): import { ChartSyncProvider, LineChart, BarChart, type ChartSeries } from "@sheenui/theme";
const revenue = [
{ month: "Jan", organic: 61000, paid: 34000 },
{ month: "Feb", organic: 64500, paid: 36500 },
{ month: "Mar", organic: 69000, paid: 38200 },
{ month: "Apr", organic: 72800, paid: 41000 },
];
const revenueSeries: ChartSeries[] = [
{ key: "organic", label: "Organic", color: 1 },
{ key: "paid", label: "Paid", color: 2 },
];
const signups = [
{ month: "Jan", signups: 1240, activated: 780 },
{ month: "Feb", signups: 1310, activated: 820 },
{ month: "Mar", signups: 1490, activated: 930 },
{ month: "Apr", signups: 1420, activated: 900 },
];
const signupSeries: ChartSeries[] = [
{ key: "signups", label: "Signups", color: 1 },
{ key: "activated", label: "Activated", color: 3 },
];
export function Example() {
return (
<ChartSyncProvider>
<LineChart data={revenue} index="month" series={revenueSeries} aria-label="Revenue" />
<BarChart data={signups} index="month" series={signupSeries} aria-label="Signups" />
</ChartSyncProvider>
);
}Annotations
Reference lines and bands on the value axis, event markers and ranges on the x axis. Labels sit on a surface plate, in text colors; events are also read out with their data point.
import { LineChart } from "@/components/sheenui/charts/line-chart";
// Package build (after the first npm release, or a packed tarball): import { LineChart } from "@sheenui/theme";
const data = [
{ month: "Jan", organic: 61000 },
{ month: "Feb", organic: 64500 },
{ month: "Mar", organic: 69000 },
{ month: "Apr", organic: 72800 },
{ month: "May", organic: 78100 },
{ month: "Jun", organic: 83400 },
];
export function Example() {
return (
<LineChart
data={data}
index="month"
series={[{ key: "organic", label: "Organic" }]}
annotations={[
{ type: "band", from: 60000, to: 75000, label: "Forecast range" },
{ type: "line", value: 80000, label: "Goal $80K", tone: "accent" },
{ type: "range", from: "Jan", to: "Feb", label: "Holiday freeze" },
{ type: "event", at: "Jun", label: "Pricing change", tone: "warning" },
]}
aria-label="Organic revenue with goal and events"
/>
);
}Export, locale and labels
exportable adds a download menu: PNG and SVG keep the exact colors of the current theme, CSV has the raw numbers. Every string is a label, and numbers follow the locale (German here).
import { ChartCard } from "@/components/sheenui/charts/chart-parts/chart-card";
import { ChartTable } from "@/components/sheenui/charts/chart-parts/empty-table";
import { type ChartSeries } from "@/components/sheenui/charts/chart-utils";
import { AreaChart } from "@/components/sheenui/charts/line-chart";
// Package build (after the first npm release, or a packed tarball): import { ChartCard, ChartTable, AreaChart, type ChartSeries } from "@sheenui/theme";
const eur = new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR", maximumFractionDigits: 0 });
const data = [
{ month: "Jan", revenue: 61000 },
{ month: "Feb", revenue: 64500 },
{ month: "Mär", revenue: 69000 },
{ month: "Apr", revenue: 72800 },
];
const series: ChartSeries[] = [{ key: "revenue", label: "Umsatz", color: 1 }];
export function Example() {
return (
<ChartCard
title="Umsatz"
exportable
labels={{ chart: "Diagramm", table: "Tabelle", downloadPng: "Als PNG herunterladen", noData: "Keine Daten" }}
table={<ChartTable data={data} index="month" series={series} format={(n) => eur.format(n)} />}
>
<AreaChart data={data} index="month" series={series} locale="de" format={(n) => eur.format(n)} labels={{ previous: (l) => l + " (Vorperiode)" }} aria-label="Umsatz pro Monat" />
</ChartCard>
);
}Live data
useLiveData appends a row on an interval into a sliding window and pauses off-screen, in hidden tabs and on Pause. With live, new points slide in from the right instead of morphing.
import { Button } from "@/components/sheenui/button/button";
import { useLiveData, type ChartRow, type ChartSeries } from "@/components/sheenui/charts/chart-utils";
import { LineChart } from "@/components/sheenui/charts/line-chart";
// Package build (after the first npm release, or a packed tarball): import { Button, LineChart, useLiveData, type ChartRow, type ChartSeries } from "@sheenui/theme";
import { useRef } from "react";
const initial: ChartRow[] = [
{ t: "0s", v: 800 },
{ t: "2s", v: 830 },
];
const series: ChartSeries[] = [{ key: "v", label: "Requests" }];
export function RequestsPerSecond() {
const ref = useRef<HTMLDivElement>(null);
const { data, paused, setPaused } = useLiveData(initial, {
next: (rows, tick) => ({ t: tick * 2 + "s", v: Math.round(Number(rows[rows.length - 1]?.v ?? 800) + (Math.random() - 0.5) * 140) }),
interval: 1500,
max: 16,
ref, // pauses while this element is off-screen
});
return (
<>
<div ref={ref}>
{/* data takes a mutable array: spread the hook's read-only window */}
<LineChart live data={data} index="t" series={series} aria-label="Requests per second" />
</div>
<Button onClick={() => setPaused(!paused)}>{paused ? "Resume" : "Pause"}</Button>
</>
);
}API
Series take a color slot from 1 to 8 (the validated palette, assigned in order when omitted, never re-ranked when a series is hidden). Every chart needs an aria-label; pair it with a ChartTable so every value can be read without color.
Show the prop tables for every chart, card and helper
LineChart / AreaChart
LineChartLabels keys and English defaults (3)
BarChart
BarChartLabels keys and English defaults (3)
DonutChart
DonutChartLabels keys and English defaults (7)
RadialProgress
RadialProgressLabels keys and English defaults (4)
Sparkline
SparklineLabels keys and English defaults (1)
ChartCard / ChartTable / ChartLegend
ChartCardLabels keys and English defaults (19)
Sync, brush, annotations, export, live data
ChartAnnotationsLayer props
ChartAnnouncer props
ChartBrush props
ChartBrushLabels keys and English defaults (4)
ChartSyncProvider props
ChartTooltip props
LegendKey props
TableScroll props
Keyboard
Accessibility
- Every interactive chart is a focusable figure named by its title and described by the reading instructions (the same key on every chart, `labels.instructions`, a string or a function); inside a ChartCard with a table, `aria-details` points at the table view. The active values are announced once, politely.
- Every chart has a table view (Chart / Table tabs), so no value depends on color or on seeing the marks.
- Legend keys are toggle buttons (pressed = shown); hiding or showing a series is announced.
- Event markers are read out with the data point they sit on; status colors always come with a word or an icon.
- Reduced motion: charts appear at their final values, data changes jump, and live charts stop sliding.
- Windows High Contrast: legend keys gain outlines, the active tab and brush window use system colors.
All exports on this page
Show all 37 exports
ChartAnnotationsLayer— Draws annotations inside a chart's plot group (already translated to the plot origin).ChartAnnouncer— Screen-reader announcement of the active data point (charts are keyboard-navigable).ChartBrush— Memoised: the chart above re-renders on every pointer move, the brush only when its range does.ChartCard— A glass card with header, legend and (when table is given) Chart / Table tabs.ChartLegend— Legend keys mirror the mark: a short line for line charts, a swatch for bars/areas.ChartSyncProvider— Groups charts so one reading drives all of them.ChartTable— Every chart has a table view: the accessible, colour-free way to read every value.ChartTooltip— Glass tooltip positioned inside the chart container.ChartWidthHint— The width (px) charts inside can assume before they have measured themselves, e.g.LegendKey— The colour key for a series, drawn as SVG (not a CSS background) so it survives forced-colors / Windows High Contrast.RadialProgress— A single ratio against a limit.TableScroll— Horizontal scroll container for a table view: when the table is wider than the card, it scrolls inside (never the page).annotationColors— Stroke / fill / text colours for a tone (tokens only).annotationValues— Values the value axis should include so every reference line and band is on screen.chartTooltipSurface— Classes + style for a chart tooltip surface (for charts that build their own tooltip).clampBrushRange— Keep a range inside [0, count - 1] with at least minSpan rows.createChartSyncStore— A standalone sync store, for syncing charts that don't share a parent (pass it as store).defaultBrushRange— A sensible starting window: the last fraction of count rows (at least minSpan).defaultChartBrushLabels— The built-in English strings of ChartBrush; spread it into your own labels and change what you need.defaultChartCardLabels— The built-in English strings of ChartCard; spread it into your own labels and change what you need.defaultChartLegendLabels— The built-in English strings of ChartLegend; spread it into your own labels and change what you need.defaultChartTableLabels— The English strings of ChartTable (and of the empty state); a ChartCard's labels override them below it.defaultRadialProgressLabels— The built-in English strings of RadialProgress; spread it into your own labels and change what you need.dockSpace— Height to reserve above the plot for the docked readout (touch screens): the lines the widest readout ANY point produces.eventsAt— Event markers that sit on row i (read out with that row's values).fitTicks— Round ticks that hug the data AND fit the axis.formatCompact— 1,284 · 12.9K · 4.2M · −640localeTickFormat— formatTick for any locale: ticks keep exactly the decimals their step needs (0.25 stays 0,25 in German), compact from 10,000.percentChange— Signed percent change from previous to current ("+12.4%", "−3%"), or null when undefined.seriesLegend— Builds the ChartLegend items for a list of series (colour by position, key shape line or rect).useChartFrame— useElementWidth that also hands back the element itself (for in-view checks, exports and pointer maths).useChartSeriesState— Hidden / highlighted series state for building your own interactive legend + chart pair.useChartSeriesVisibility— For chart authors: the series visibility to draw with.useChartSharedLabels— Text a ChartCard hands down to its table and empty states (labels.noData, labels.previous).useChartSync— For chart authors.useElementInView— Whether element is in the viewport (IntersectionObserver).withMinimum— Give every non-zero length at least min (so a 0.1% share still draws a visible mark), taking the room from the larger ones in proportion.
Related pages
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .