Skip to content

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.json

Sessions by channel

  • Organic
  • Paid
  • Referral
  • Social
Use left and right arrow keys to read values.

  • StackedAreaChart
  • StackedAreaTable
  • defaultStackedAreaChartLabels
  • +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

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.tsx
  • components/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.ts
  • lib/{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

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

StackedAreaChart props

PropTypeDefaultDescription
data (required)readonly ChartRow[]NoneOne object per point: the index key plus one number per series key.
index (required)stringNoneKey of the x value in each row (e.g. "month").
series (required)readonly ChartSeries[]NoneBands from the bottom of the stack up. Give each a fixed color slot so filtering never repaints it.
mode"stacked" | "percent""stacked""stacked": bands add up to the total. "percent": every x position is scaled to 100%, so the bands show each series' share. A point whose values add up to 0 has no shares: the bands break around it (a gap, marked with a dashed "no data" column) instead of dipping to 0%.
curve"linear" | "monotone""linear""linear" joins points with straight lines; "monotone" with smooth curves that never overshoot a value.
heightnumber260Height of the chart in px; the width follows the container.
format((n: number) => string)formatCompactFormats values in the tooltip (and the axis in "stacked" mode). Negative values count as 0.
formatPercent((n: number) => string)formatPercentDefaultFormats shares (0–100) in "percent" mode.
emptyStateReactNodeNoneShown when there is nothing to plot.
patternsbooleantrue when series.length > 3Tell series apart without colour (hatch fills, dash styles, marker shapes).
labelsPartial<StackedAreaChartLabels>defaultStackedAreaChartLabelsEvery other string, for translation: labels={{ total: "…" }}; omitted keys keep the English of defaultStackedAreaChartLabels. All 4 keys of StackedAreaChartLabels are listed in the key table under the props table.
aria-label (required)stringNoneAccessible summary of what the chart shows.
classNamestringNoneAdds extra classes to the outer element.
StackedAreaChartLabels keys and English defaults (4)
Pass any key in labels; the rest keep the defaults of defaultStackedAreaChartLabels.
KeyEnglish default
totalTotal
noDataNo data
instructionsUse left and right arrow keys to read values.
touchHintTap or drag across the chart to read values.

StackedAreaTable props

PropTypeDefaultDescription
data (required)readonly ChartRow[]NoneTakes the same rows as the chart.
index (required)stringNoneKey of each row that names its position on the axis.
series (required)readonly ChartSeries[]NoneTakes the same series as the chart.
mode"stacked" | "percent""stacked"Match the chart: "percent" shows each share beside the value it comes from.
format((n: number) => string)formatCompactFormats a value for the data table cells: takes the number, returns the text shown.
formatPercent((n: number) => string)formatPercentDefaultFormats shares in percent mode.
indexLabelstringindexSets the header of the first column.
captionstringNoneVisually hidden caption naming the table (also names its scroll region).
labelsPartial<Pick<StackedAreaChartLabels, "total" | "noData">>defaultStackedAreaChartLabelsOverride the "Total" column header and the empty text. Every other string, for translation: labels={{ total: "…" }}; omitted keys keep the English of defaultStackedAreaChartLabels. All 2 keys of StackedAreaChartLabels are listed in the key table under the props table.
classNamestringNoneAdds extra classes to the outer element.

Keyboard

KeysAction
TabFocus the chart. It is one tab stop; the arrow keys then read it.
←/→Previous / next point.
Home/EndJump to the first / last point.
EscapeClear the reading.
Enter/Spaceon a legend keyHide or show that series (inside a ChartCard).

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

48 charts pages in all: browse them on Charts.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .