Area chart
A line with a light wash to zero, for volume over time.
A total over time and what it's made of, in absolute terms or as 100% shares.
<StackedAreaChart />Stacked area chart is free under the MIT license.
$ npx shadcn@latest add https://chartslibraryui.com/r/stacked-area-chart.jsonInstalls the chart, its dependencies and the shared core into your components folder.
Then import the theme once: import "@/components/charts/core/charts.css" Installation guide
import { StackedAreaChart } from "@/components/charts/stacked-area-chart";
import { revenueByPlan } from "./sample-data";
export function Example() {
return (
<StackedAreaChart
title="Enterprise drove most of this year's growth"
subtitle="Monthly revenue by plan, USD"
data={revenueByPlan}
x="month"
series={plans}
format="currency"
/>
);
}
Rows with an x key and one non-negative numeric key per layer.
[{ month: "Jan", starter: 88000, team: 164000, business: 212000 }, ...]Missing values are null. Invalid values make the chart say what’s wrong instead of drawing a misleading picture. How charts handle bad data
Every chart also accepts the shared frame props: title, subtitle, source, height, mode, toolbar. Common API
export interface StackedAreaChartProps extends Omit<SeriesChartProps, "zero" | "highlight"> {
/** Show each series as a share of the total (100% stacked). */
normalize?: boolean;
}
// from core/series.tsx
export interface SeriesChartProps extends FrameProps {
data: Row[];
/** Key of the x value in each row. */
x: string;
series: SeriesInput[];
/** "category" treats x as labels (default); "time" reads ISO strings, Date or ms and spaces by real time. */
xType?: "category" | "time";
/** Date grain used to label time axes and tooltips. Auto-detected if omitted. */
grain?: DateGrain;
/** Y value format, e.g. "currency", { kind: "percent" }, or a function. */
format?: FormatInput;
curve?: Curve;
/** Series key(s) to emphasise; others are drawn as grey context. */
highlight?: string | string[];
/** First x value that is a forecast. From there on lines are dashed and the region is shaded. */
forecastFrom?: string | number | Date;
/** First x value that is an incomplete period (e.g. month to date). */
partialFrom?: string | number | Date;
/** Include zero in the y axis. Default true; set false to zoom in on a rate (lines only). */
zero?: boolean;
/** Fixed y domain; null keeps the computed bound. */
yDomain?: [number | null, number | null];
references?: Reference[];
/** Dots on every point. Default: only when there are few points. */
markers?: boolean;
/** Series names at the line ends. Default: on when up to 4 series fit. */
endLabels?: boolean;
/** Show the legend. Default: on for 2+ series. */
legend?: boolean;
/** Click legend entries to hide/show series. Default true for 2+ series. */
toggleable?: boolean;
}Installs stacked-area-chart.tsx and the shared core/ (11 files).
"use client";
import { SeriesChart, type SeriesChartProps } from "./core/series";
export interface StackedAreaChartProps extends Omit<SeriesChartProps, "zero" | "highlight"> {
/** Show each series as a share of the total (100% stacked). */
normalize?: boolean;
}
/**
* A total over time and what it is made of. Negative values are rejected because they can't be stacked honestly.
* A missing value in any series leaves a gap for the whole column rather than a misleading total.
*/
export function StackedAreaChart({ normalize, ...props }: StackedAreaChartProps) {
return (
<SeriesChart
kind={normalize ? "stacked100" : "stacked"}
summaryName={normalize ? "100% stacked area" : "stacked area"}
endLabels={false}
{...props}
zero
/>
);
}
A line with a light wash to zero, for volume over time.
Totals and their parts, with negatives stacked below zero.
100% columns joined by bands, showing how a mix changes across periods.