Streamgraph for React
A React streamgraph shows how a mix swells and fades over time as stacked areas flowing around a moving center line. Pass data as readonly ChartRow[]: one row per x value.
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/streamgraph.jsonListening by genre
StreamgraphStreamgraphTableinsideOutOrderstreamBaselinefoldStreamSeries- +5 more
- +2 more
A year of listening
Seven genres over 52 weeks. Hover a layer to bring it forward; use left / right to move through time and up / down to pick a layer. Switch the baseline to compare wiggle and silhouette.
Listening by genre
Hours per week, Nov 2025 to Oct 2026, by genre
- Pop
- Hip-hop
- Rock
- Electronic
- Jazz
- Classical
- Lo-fi
import { ChartCard } from "@/components/sheenui/charts/chart-parts/chart-card";
import { type ChartRow, type ChartSeries } from "@/components/sheenui/charts/chart-utils";
import { Streamgraph } from "@/components/sheenui/charts/streamgraph";
import { streamgraphLegend } from "@/components/sheenui/charts/streamgraph/model";
import { StreamgraphTable } from "@/components/sheenui/charts/streamgraph/parts";
// Package build (after the first npm release, or a packed tarball): import { ChartCard, streamgraphLegend, StreamgraphTable, Streamgraph, type ChartRow, type ChartSeries } from "@sheenui/theme";
const series: ChartSeries[] = [
{ key: "pop", label: "Pop", color: 5 },
{ key: "hiphop", label: "Hip-hop", color: 2 },
{ key: "rock", label: "Rock", color: 8 },
];
const data: ChartRow[] = [
{ week: "Nov 3", pop: 6.2, hiphop: 4.1, rock: 2.8 },
{ week: "Nov 10", pop: 6.8, hiphop: 4.4, rock: 2.5 },
{ week: "Nov 17", pop: 7.4, hiphop: 3.9, rock: 2.2 },
{ week: "Nov 24", pop: 7.0, hiphop: 4.8, rock: 2.6 },
{ week: "Dec 1", pop: 8.1, hiphop: 5.2, rock: 3.0 },
{ week: "Dec 8", pop: 7.6, hiphop: 4.6, rock: 3.4 },
];
const oneDecimal = new Intl.NumberFormat("en", { maximumFractionDigits: 1 });
const hours = (n: number) => oneDecimal.format(n) + " h";
export function Example() {
return (
<ChartCard
title="Listening by genre"
legend={streamgraphLegend(series)}
table={<StreamgraphTable data={data} index="week" series={series} format={hours} />}
>
<Streamgraph data={data} index="week" series={series} offset="wiggle" format={hours} aria-label="Weekly listening hours by genre" />
</ChartCard>
);
}Files to copy
16 folders · 33 files · 4 packages
- From
theme/src/ components/charts/{streamgraph.tsx, category-bar.tsx, chart-export-menu.tsx, chart-export.ts, chart-figure.tsx, chart-fit.tsx, chart-icons.tsx, chart-parts.tsx, chart-patterns.tsx, chart-pointer.tsx, chart-tip.tsx, chart-utils.ts, heatmap.tsx}components/button/components/charts/category-bar/components/charts/chart-parts/components/charts/heatmap/components/charts/streamgraph/components/drawer/parts/sheet.tsxcomponents/kbd/components/menu/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}motion/{gate.ts, tokens.ts}lib/{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/streamgraph.jsonRegistry item: streamgraph. 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".
Traffic sources around a launch
Thirty days of visits by source, with a launch spike in week three. Silhouette or wiggle, the total is always the stream's thickness.
Visits by source
Last 30 days
- Search
- Direct
- Social
- Referral
import { type ChartRow, type ChartSeries } from "@/components/sheenui/charts/chart-utils";
import { Streamgraph } from "@/components/sheenui/charts/streamgraph";
// Package build (after the first npm release, or a packed tarball): import { Streamgraph, type ChartRow, type ChartSeries } from "@sheenui/theme";
const sources: ChartSeries[] = [
{ key: "search", label: "Search", color: 1 },
{ key: "social", label: "Social", color: 2 },
{ key: "referral", label: "Referral", color: 3 },
{ key: "email", label: "Email", color: 7 },
];
const traffic: ChartRow[] = [
{ day: "Day 1", search: 1800, social: 640, referral: 1100, email: 420 },
{ day: "Day 8", search: 1850, social: 700, referral: 1150, email: 400 },
{ day: "Day 15", search: 2300, social: 1900, referral: 2600, email: 2400 },
{ day: "Day 22", search: 2100, social: 1200, referral: 1700, email: 450 },
{ day: "Day 30", search: 1950, social: 800, referral: 1300, email: 430 },
];
export function Example() {
return <Streamgraph data={traffic} index="day" series={sources} height={260} aria-label="Daily visits by source" />;
}Props
StreamgraphLabels keys and English defaults (5)
StreamgraphTable props
Keyboard
Accessibility
- The chart is one focusable figure; each step through time announces every layer's value and share, largest first, then the total. With a layer picked, only that layer is read.
- Layer names sit on solid tags of the chart surface, so they meet AA contrast on any layer color; layers that are too thin for a name rely on the legend and the tooltip.
- Color slots are fixed per series and never repeat: more than 8 layers fold into a gray “Other”.
- On phones the readout docks above the plot instead of covering it; vertical swipes keep scrolling the page.
- The table view lists every value with a total column. Reduced motion draws the layers in place.
All exports on this page
Streamgraph— Stacked areas flowing around a moving centre line: how a mix of categories swells and fades over time (genres, topics, traffic sources).StreamgraphTable— One row per x value, one column per layer, plus the total.defaultStreamgraphLabels— The built-in English strings of Streamgraph; spread it into your own labels and change what you need.foldStreamSeries— Fold series past the 8th into one "Other" layer (neutral grey).insideOutOrder— Inside-out order (Byron & Wattenberg): series that peak early and late go to the edges, the ones peaking mid-way sit in the middle.streamBaseline— Baseline per x of a stream: "wiggle" minimises the layers' weighted slope (Byron & Wattenberg's streamgraph, as d3's stackOffsetWiggle).streamgraphLegend— Legend for a streamgraph: one swatch per layer, as folded.
When to use Streamgraph
- Use it as a stream chart for a year of listening hours by genre, where the shape of each layer shows how a mix swells and fades across 52 weeks.
- It suits traffic sources around a launch, with thirty days of visits by source and a spike in week three, where the stream's thickness is always the total.
- It works for any many-category time series where totals matter less than the rhythm of change, with layer names printed inside their thickest stretch when they fit.
- Skip it when readers must read exact values or compare layers against a common baseline; StackedAreaChart keeps a flat bottom, and LineChart compares individual series better.
- Pair it with ChartCard and its legend, StreamgraphTable for exact values as text, and a SegmentedControl to switch offset between wiggle and silhouette.
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 .