Skip to content
WunderUI

Stacked Chart

Pro

Stacked chart for the parts of a total: stacked and 100 % columns, stacked areas, diverging Likert bars, Marimekko and gapped rows.

Playground

Stacked Charts

Stacked chart, 12 points from Jan to Dec. Direct from 14k to 27k, lowest 14k, highest 27k; Organic from 10k to 17k, lowest 10k, highest 17k; Referral from 5k to 11k, lowest 5k, highest 11k.
Stacked Charts, data table
monthDirectOrganicReferral
Jan14k10k5k
Feb18k11k7k
Mar16k10k6k
Apr20k14k8k
May19k13k7k
Jun23k15k9k
Jul21k14k8k
Aug25k16k10k
Sep22k15k9k
Oct20k13k8k
Nov24k16k10k
Dec27k17k11k

Installation

Stacked Chart comes with WunderUI Core and Pro, in the package from your plan. See the plans.

The charts live in their own entry point: import the chart, its card and its hooks from @wunderui/react/charts, not from @wunderui/react.

Then import what you need:

tsx
import {
  StackedChart,
  StackedChartProps,
  StackedChartVariant,
} from "@wunderui/react/charts"

Then use it:

tsx
import { StackedChart } from "@wunderui/react/charts"

const data = [
  { month: "Jan", direct: 14000, organic: 10000 },
  { month: "Feb", direct: 18000, organic: 11000 },
  { month: "Mar", direct: 16000, organic: 10000 },
  { month: "Apr", direct: 20000, organic: 14000 },
]

export function SessionsByChannel() {
  return (
    <StackedChart
      data={data}
      index="month"
      series={[
        { key: "direct", label: "Direct" },
        { key: "organic", label: "Organic" },
      ]}
      label="Sessions by channel"
    />
  )
}

Expected result: You see four columns, each made of a Direct and an Organic part stacked on one zero line.

When to use

Use Stacked Chart for

  • The parts that make up a total, per category or period
  • Shares of a whole over time (the 100 % variants)
  • Survey answers on a scale (the diverging stack)
  • Two dimensions at once: the width of a column says how big a group is (Marimekko)

Use something else for

  • Bar Chart for comparing single values or a few series side by side
  • Pie Chart for the parts of one total, at one moment
  • Area Chart for overlapping series that are not parts of one total
  • Treemap for parts of a hierarchy

States

Loading, empty and error keep the chart's size, so the card never jumps. Add a retry handler and the error state offers a Try again button.

Stacked Charts

Stacked chart, 12 points from Jan to Dec. Direct from 14k to 27k, lowest 14k, highest 27k; Organic from 10k to 17k, lowest 10k, highest 17k; Referral from 5k to 11k, lowest 5k, highest 11k.
Stacked Charts, data table
monthDirectOrganicReferral
Jan14k10k5k
Feb18k11k7k
Mar16k10k6k
Apr20k14k8k
May19k13k7k
Jun23k15k9k
Jul21k14k8k
Aug25k16k10k
Sep22k15k9k
Oct20k13k8k
Nov24k16k10k
Dec27k17k11k

Table view

Every chart carries a table of its data for screen readers. A ChartCard can show it on screen too, with a toggle in the header.

Sessions

Stacked chart, 12 points from Jan to Dec. Direct from 14k to 27k, lowest 14k, highest 27k; Organic from 10k to 17k, lowest 10k, highest 17k; Referral from 5k to 11k, lowest 5k, highest 11k.
Sessions by channel, data table
monthDirectOrganicReferral
Jan14k10k5k
Feb18k11k7k
Mar16k10k6k
Apr20k14k8k
May19k13k7k
Jun23k15k9k
Jul21k14k8k
Aug25k16k10k
Sep22k15k9k
Oct20k13k8k
Nov24k16k10k
Dec27k17k11k

Keyboard interactions

The plot is focusable, so the chart works without a pointer.

TaborShiftTab
Moves focus to the plot and away from it. The plot is one tab stop; so is every legend badge.
ArrowRightorArrowLeft
Moves to the next or previous category. The tooltip follows, and a live region announces the one you are on. The first press starts at the first one (Left: the last one).
HomeorEnd
Jumps to the first or last category.
ShiftArrowRightorShiftArrowLeft
Extends a selected range from the point you started on. A range is only selected when is set.
Escape
Clears the active point and the selected range.
EnterorSpace
On a legend badge of a ChartCard: switches its series off or on. The last visible series stays on.

On horizontal and diverging stacks the categories run top to bottom, so Up and Down walk them instead of Left and Right.

Behavior and motion

What the chart does on its own and what the page decides.

Stacking order
Series stack in the order you list them, from the bottom or left. Put the part that matters most there, where the eye compares it best.
Normalized variants
The 100 percent bar and area variants and the Marimekko scale every stack to 100. The axis reads percent while the tooltip and table still show the raw amounts.
Diverging stack
The diverging bar puts 0 in the middle. You say how many series, counted from the first, go to the left (default: half of them).
Segments
Gap and bar width shape the segments, and the Marimekko percentages can be toggled. A series switched off in the legend keeps its place and fades, so the rest of the stack doesn't jump.
Loading, empty and error
The chart keeps its size while loading, empty or failed, so the card never jumps. Add a retry handler to show a Try again button on error.
Legend
A ChartCard shows the series as badges. With two or more series each badge switches its series off, but the last visible one stays on.
Data table
The chart renders its data as a table for screen readers, in the same order as the plot. A ChartCard can show that table on screen through a toggle that keeps the card's height.
Size
The chart fills the width of its container, and you set the plot height. Text never scales, so labels keep their size at every width.

Motion

The enter sequence and the hover follow the library's motion tokens.

Grow
Segments grow from the baseline (areas wipe in) when the chart first comes into view, after loading and when the data changes.
Hover
The bar variants light a muted band behind the category. The area variants follow it with a ringed point on top of each stack.
Reduced motion
With reduced motion the chart appears at once. The tooltip, the crosshair and every state still work.

Anatomy

A stacked chart splits each category into its parts, as columns, areas, 100 percent stacks, horizontal rows, a diverging Likert stack or a Marimekko whose column width is the share.

Sessions

Stacked chart, 12 points from Jan to Dec. Direct from 14k to 27k, lowest 14k, highest 27k; Organic from 10k to 17k, lowest 10k, highest 17k; Referral from 5k to 11k, lowest 5k, highest 11k.
Sessions by channel, data table
monthDirectOrganicReferral
Jan14k10k5k
Feb18k11k7k
Mar16k10k6k
Apr20k14k8k
May19k13k7k
Jun23k15k9k
Jul21k14k8k
Aug25k16k10k
Sep22k15k9k
Oct20k13k8k
Nov24k16k10k
Dec27k17k11k
  • Takes the data, an index field and the series in stacking order, from the bottom or left. Options split a diverging stack, shape the segments and toggle the Marimekko percentages.

  • data-slot="chart-plot"

    The focusable region. Arrow keys walk the categories (Up and Down for horizontal stacks), and Shift with an arrow or a drag selects a range.

  • data-slot="chart-grid"

    A value axis from 0, or 0 to 100 percent on the normalized variants and the Marimekko. Diverging stacks put 0 in the middle and the negative side on the left.

  • data-slot="chart-marks"

    One segment per series and category, stacked in order. A series switched off in the legend keeps its place and fades, so the rest of the stack doesn't jump.

  • data-slot="chart-active"Optional

    On the two area variants, a ringed point on top of each stack follows the hovered category. The bar variants use the hover band instead.

  • data-slot="chart-tooltip"Optional

    The category and one row per visible part with its raw value, plus a change chip for the first series. Normalized variants still show amounts here while the axis reads percent.

  • data-slot="chart-message"Optional

    A bar-shaped skeleton while loading. The empty and error messages replace the stack.

  • A hidden table with the raw values, not percentages, so screen readers hear the same numbers the tooltip shows.

Best practices

  • Do

    Order the series by importance, with the part people compare most at the baseline. Only the bottom (or left) segment shares a common start, so only it can be compared exactly.

  • Do

    Switch to a 100 percent variant when the shares matter and the totals do not. All bars then reach 100 and segment sizes are comparable between categories.

  • Do

    Use the diverging variant for survey scales such as strongly disagree to strongly agree. With an odd number of series the middle one is neutral and straddles zero.

  • Don’t

    Don't stack more than five series. Thin segments lose their labels and hover target, and the hues get hard to match to the legend.

  • Don’t

    Don't stack values that aren't additive, such as averages or rates. A stack implies the parts sum to the total.

API reference

One table for StackedChart, listing every prop. The ChartCard around it has its own props, and the chart also works without one.

Takes the data, an index field and the series in stacking order, from the bottom or left. Options split a diverging stack, shape the segments and toggle the Marimekko percentages.

PropTypeDefaultDescription
data requiredreadonly ChartDatum[]—One object per category / point.
index requiredstring—Field holding the category label (x axis; y axis for horizontal bars).
series requiredreadonly ChartSeries[]—The series to draw, in order.
variant"stacked-bar" | "stacked-bar-100" | "horizontal-stacked-bar" | "stacked-area" | "stacked-area-100" | "stacked-gradient-bar" | "diverging-stacked-bar" | "marimekko" | "gapped-horizontal-stacked-bar""stacked-bar"Figma variant. Default .
valueFormatterChartValueFormatter—Values in tooltip, labels, table and live region. Default: 42000 → "42k".
labelstring—Accessible name, e.g. the card title.
heightnumber—Height of the plot frame in px. Default 434 = the plot of the Figma large card.
state"ready" | "loading" | "empty" | "error"— shows the chart-shaped skeleton, and a message in the plot.
hiddenSeriesreadonly string[]—Series keys that are switched off (legend toggle): drawn faded, dimmed in the tooltip.
negativeCountnumber—: how many of the first series go to the left of zero (default: half, rounded down; with an odd count the middle series is neutral and straddles zero — a Likert scale).
showSegmentLabelsbooleantrueSegment labels inside the marimekko cells ("39 %"). Default true.
segmentGapnumber—Gap between stacked segments in px (default 0; gapped rows 4).
activeIndexnumber | null—The active point (hovered or focused) as an index into , to control it yourself. shows none.
animateboolean—Enter sequence (draw, wipe, grow) on scroll into view, after loading and on new data. Default true; off with reduced motion.
animationKeystring | number—Change it to play the enter sequence again (e.g. ). New replays it by itself.
axisFormatterChartValueFormatter—Value-axis labels; defaults to .
barWidthnumber—Maximum bar width (thickness for horizontal stacks) in px.
categoryAxisboolean—Category-axis labels (default true).
categoryFormatter(label) => string—Shortens category labels on the axis, e.g. "Mar 12" → "Mar"; tooltip and pill keep the full label.
categoryTicksreadonly string[]—Only these category labels are shown on the axis (the rest stay hoverable).
defaultActiveIndexnumber | null—The point that is active at first, for an uncontrolled chart. It shows the tooltip without a pointer.
defaultSelectedRangeChartRange | null—The range that is selected at first, for an uncontrolled chart.
descriptionstring—Screen-reader summary; generated from the data when omitted.
emptyDescriptionstring—Text under the title in the empty state.
emptyTitlestring—Title of the message in the empty state.
errorDescriptionstring—Text under the title in the error state.
errorTitlestring—Title of the message in the error state.
gridboolean—Grid lines (default true).
gridIntervalsnumber—Number of equal grid intervals (default 6 = 7 grid lines like the Figma cards).
gridStyle"solid" | "dashed"— draws the grid lines 4 / 4 dashed (dense dashboards).
includeZeroboolean—The value axis starts at 0 (owner rule, default). fits the data (prices, temperatures).
onActiveIndexChange(index) => void—Called with the index when the pointer or the arrow keys move to another point, and with when they leave. Use it to show the hovered value in a headline.
onRetry() => void—Shows a Try again button in the error state and calls this when it is pressed.
onSelectedRangeChange(range) => void—Called when a drag across the plot or Shift with an arrow key changes the range, and with when Escape or a click clears it.
rangeSelectableboolean—Allow selecting a range by dragging or Shift + arrow keys. On when is set.
selectedRangeChartRange | null—The selected range as inclusive indices into , to control it yourself. selects nothing.
tooltipboolean—Tooltip on hover / keyboard focus. Default true.
tooltipTitle(datum, index) => ReactNode—Title line of the tooltip; defaults to the category label.
valueAxisboolean—Value-axis labels (default true). Off for compact cards and sparkline-like plots.
valueAxisSide"left" | "right"—Side of the value axis (vertical charts). is the price axis of trading charts.
valueDomainreadonly [number, number]—Fix the value domain instead of fitting it to the data (still rounded to nice steps).
valueTicksreadonly number[]—Exact value-axis ticks (ascending), e.g. [0, 10000, … 70000]; replaces the nice-step domain.
widthnumber—Fixed width instead of filling and measuring the container.

Notes for AI

Give your coding assistant the Markdown reference instead of screenshots.

MCPget_component("stacked-chart")
InstallIncluded in Core and Pro

The full library index for assistants is at /llms.txt.