Stacked Area Chart for React
A React stacked area chart shows how a total builds from its parts over time, or in 100% mode how the mix shifts. Pass data as readonly ChartRow[]: one object per point: the index key plus one number per series key.
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/stacked-area-chart.jsonSessions by channel
- Organic
- Paid
- Referral
- Social
StackedAreaChartStackedAreaTabledefaultStackedAreaChartLabels- +1 more
Stacked and 100% stacked
Switch the mode, the curve and the range: the bands morph between them. Hover, tap, or focus the chart and use the arrow keys.
Sessions by channel
Monthly sessions
- Organic
- Paid
- Referral
- Social
import { ChartCard } from "@/components/sheenui/charts/chart-parts/chart-card";
import { seriesLegend } from "@/components/sheenui/charts/chart-parts/legend-tooltip";
import { type ChartSeries } from "@/components/sheenui/charts/chart-utils";
import { StackedAreaTable, StackedAreaChart } from "@/components/sheenui/charts/stacked-area-chart";
// Package build (after the first npm release, or a packed tarball): import { ChartCard, seriesLegend, StackedAreaTable, StackedAreaChart, type ChartSeries } from "@sheenui/theme";
const data = [
{ month: "Jun", organic: 41000, paid: 23000, referral: 9800, social: 6400 },
{ month: "Jul", organic: 44200, paid: 24100, referral: 10300, social: 7100 },
{ month: "Aug", organic: 46900, paid: 26800, referral: 11200, social: 7600 },
{ month: "Sep", organic: 49100, paid: 27500, referral: 11900, social: 8800 },
{ month: "Oct", organic: 52300, paid: 29400, referral: 12600, social: 9300 },
];
const series: ChartSeries[] = [
{ key: "organic", label: "Organic", color: 1 },
{ key: "paid", label: "Paid", color: 2 },
{ key: "referral", label: "Referral", color: 3 },
{ key: "social", label: "Social", color: 4 },
];
export function Example() {
return (
<ChartCard
title="Sessions by channel"
legend={seriesLegend(series, "rect")}
table={<StackedAreaTable data={data} index="month" series={series} mode="stacked" />}
>
<StackedAreaChart
data={data}
index="month"
mode="stacked" // or "percent"
curve="linear" // or "monotone"
series={series}
aria-label="Monthly sessions by channel, stacked"
/>
</ChartCard>
);
}Files to copy
11 folders · 26 files · 4 packages
- From
theme/src/ components/charts/{percent-bar-chart.tsx, stacked-area-chart.tsx, chart-export-menu.tsx, chart-export.ts, chart-figure.tsx, chart-fit.tsx, chart-icons.tsx, chart-parts.tsx, chart-patterns.tsx, chart-utils.ts}components/charts/chart-parts/components/drawer/parts/sheet.tsxcomponents/kbd/components/menu/components/skeleton/components/status-icons/hooks/{use-controllable.ts, use-intersection.ts, use-latest.ts, use-media-query.ts, use-preferences.ts}motion/tokens.tslib/{cn.ts, csv.ts, form.ts, glide-highlight.tsx, heading.ts, math.ts, popup-a11y.ts, popup-motion.ts, warn-once.ts}styles/
- shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/stacked-area-chart.jsonRegistry item: stacked-area-chart. The styles need the Tailwind v4 glass UI setup.- 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".
Share of a whole
mode="percent" scales every quarter to 100%. The tooltip leads with the share and keeps the raw value beside it; the table view shows both.
Sessions by device
Mobile overtook desktop in Q1 ’25
- Desktop
- Mobile
- Tablet
import { ChartCard } from "@/components/sheenui/charts/chart-parts/chart-card";
import { seriesLegend } from "@/components/sheenui/charts/chart-parts/legend-tooltip";
import { type ChartSeries } from "@/components/sheenui/charts/chart-utils";
import { StackedAreaTable, StackedAreaChart } from "@/components/sheenui/charts/stacked-area-chart";
// Package build (after the first npm release, or a packed tarball): import { ChartCard, seriesLegend, StackedAreaTable, StackedAreaChart, type ChartSeries } from "@sheenui/theme";
const data = [
{ quarter: "Q1 ’25", desktop: 41000, mobile: 39000, tablet: 5800 },
{ quarter: "Q2 ’25", desktop: 38500, mobile: 43500, tablet: 5500 },
{ quarter: "Q3 ’25", desktop: 36200, mobile: 47800, tablet: 5300 },
{ quarter: "Q4 ’25", desktop: 33800, mobile: 52400, tablet: 5000 },
];
const series: ChartSeries[] = [
{ key: "desktop", label: "Desktop", color: 1 },
{ key: "mobile", label: "Mobile", color: 2 },
{ key: "tablet", label: "Tablet", color: 3 },
];
export function Example() {
return (
<ChartCard
title="Sessions by device"
legend={seriesLegend(series, "rect")}
table={<StackedAreaTable mode="percent" data={data} index="quarter" series={series} />}
>
<StackedAreaChart mode="percent" curve="monotone" data={data} index="quarter" series={series} aria-label="Share of sessions by device" />
</ChartCard>
);
}Edge cases
One data point draws a flat band across the plot; a month with no values breaks a 100% chart around a dashed “no data” column instead of dipping to 0%; no data keeps the chart's footprint.
One month
- Organic
- Paid
A month with no signups
- Free
- Pro
- Team
No data
No sessions yet
import { type ChartSeries } from "@/components/sheenui/charts/chart-utils";
import { StackedAreaChart } from "@/components/sheenui/charts/stacked-area-chart";
// Package build (after the first npm release, or a packed tarball): import { StackedAreaChart, type ChartSeries } from "@sheenui/theme";
const series: ChartSeries[] = [
{ key: "organic", label: "Organic", color: 1 },
{ key: "paid", label: "Paid", color: 2 },
];
const plans: ChartSeries[] = [
{ key: "free", label: "Free", color: 1 },
{ key: "pro", label: "Pro", color: 2 },
{ key: "team", label: "Team", color: 3 },
];
const signups = [
{ month: "May", free: 420, pro: 160, team: 40 },
{ month: "Jun", free: 460, pro: 190, team: 55 },
{ month: "Jul", free: 0, pro: 0, team: 0 },
{ month: "Aug", free: 510, pro: 230, team: 70 },
];
export function Example() {
return (
<>
<StackedAreaChart data={[{ month: "Oct", organic: 41000, paid: 23000 }]} index="month" series={series} aria-label="Sessions in October" />
<StackedAreaChart mode="percent" data={signups} index="month" series={plans} aria-label="Share of signups by plan" /> {/* July adds up to 0: a gap */}
<StackedAreaChart data={[]} index="month" series={series} emptyState="No sessions yet" aria-label="Sessions" />
</>
);
}StackedAreaChart props
StackedAreaChartLabels keys and English defaults (4)
StackedAreaTable props
Keyboard
Accessibility
- The chart is one focusable figure: its aria-label is the chart title, a one-line hint describes how to read it, and in a ChartCard with a table view aria-details points at that table. Each move is announced politely, once. Each move announces every series' value and the total.
- StackedAreaTable is the same data as a real table. Pass it to ChartCard's table prop and the Chart / Table tabs let anyone read every value without color or sight.
- Reduced motion: the stacked areas appear at their final values and data changes jump instead of morphing.
All exports on this page
StackedAreaChart— Stacked areas that show how parts add up over time, in absolute values or as a share (mode="percent").StackedAreaTable— The table view of a stacked area chart: every value per x, plus the total the tooltip shows (negative values count as 0, as in the chart).defaultStackedAreaChartLabels— The built-in English strings of StackedAreaChart; spread it into your own labels and change what you need.
When to use the stacked area chart
- Use it as a stacked area graph for sessions by channel over a year, where the total and the contribution of organic, paid and referral traffic matter as the totals build up.
- It suits a 100% stacked area chart with mode percent, such as quarterly sessions by device, to show when mobile overtook desktop without the total distorting the view.
- It also handles gaps honestly: in percent mode, a month with no signups breaks the chart around a dashed no data column instead of dipping to 0%.
- Skip it when the series should be compared against each other, since stacked bands share baselines; LineChart or a grouped BarChart makes that easier, and Streamgraph suits a flowing, symmetric view.
- Pair it with ChartCard for a legend where Enter or Space on a key hides a series, StackedAreaTable for exact values, and a segmented control to switch stacked and percent modes.
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 .