Skip to the content

Charts

area-chart

A line chart with the space under each line filled flat at low opacity, optionally stacked so the series add up to a total.

Charts

When to use it

One series over time whose volume matters, or a few series that add up to a whole (stacked). To compare series that cross each other use line-chart: overlapping fills hide one another.

See it working

The demonstration the browser checks drive, with the keyboard as well as the pointer. More of it is on the Charts page.

Line chart

  • Requests
  • Errors
Example: requests and errors per day
dayRequestsErrors
Mar 1, 202612056
Mar 2, 202618076
Mar 3, 202615052
Mar 4, 202621088
Mar 5, 202626072
Mar 6, 2026240100
Mar 7, 202630084
Mar 8, 2026280120
Mar 9, 202634096
Mar 10, 2026390112
Mar 11, 2026370140
Mar 12, 2026430124

Area chart, stacked

  • Images
  • Video
  • Audio
Example: storage used per month, by kind
monthImagesVideoAudio
Jan 1, 202612306
Feb 1, 202618429
Mar 1, 2026226111
Apr 1, 2026277016
May 1, 2026358418

Bar chart

  • Web
  • App
Example: orders by channel per quarter
quarterWebApp
Q1320210
Q2410290
Q3380350
Q4460420

Donut chart

Example: traffic by source
sourcevisitsShare
Search5,20049%
Direct3,10029%
Referral1,40013%
Social9008%
  • Search5,200 · 49%
  • Direct3,100 · 29%
  • Referral1,400 · 13%
  • Social900 · 8%

Heatmap

Example: sessions by day and hour
day0910111213141516
Mon61116212681318
Tue13192581420269
Wed202711182591623
Thu271220281321614
Fri112061524101928

Radial progress, sparkline, stat

72%Storage used

Signups

1,204

+12%than last week

Add it

npx shadcn@latest add @rivier-ui/area-chart

The registry is named once in components.json: see Installation.

Example

Import it from @/components/viz/area-chart.

<AreaChart
  label="Storage used per month, by kind"
  data={[
    { month: new Date("2026-01-01"), images: 12, video: 30 },
    { month: new Date("2026-02-01"), images: 18, video: 42 },
    { month: new Date("2026-03-01"), images: 22, video: 61 },
  ]}
  x="month"
  series={[
    { key: "images", label: "Images" },
    { key: "video", label: "Video" },
  ]}
  stacked
/>

What it needs

Plain markup: it can stay a server component. No packages beyond React.

It imports

Source

The whole file. Once copied it is yours: the registry item holds the same text.

src/components/viz/area-chart.tsx
/**
 * @name area-chart
 * @category viz
 * @description A line chart with the space under each line filled flat at low opacity, optionally stacked so the series add up to a total.
 * @when One series over time whose volume matters, or a few series that add up to a whole (`stacked`). To compare series that cross each other use line-chart: overlapping fills hide one another.
 * @example
 * <AreaChart
 *   label="Storage used per month, by kind"
 *   data={[
 *     { month: new Date("2026-01-01"), images: 12, video: 30 },
 *     { month: new Date("2026-02-01"), images: 18, video: 42 },
 *     { month: new Date("2026-03-01"), images: 22, video: 61 },
 *   ]}
 *   x="month"
 *   series={[
 *     { key: "images", label: "Images" },
 *     { key: "video", label: "Video" },
 *   ]}
 *   stacked
 * />
 */
import { SeriesChart, type LineChartProps } from "@/components/viz/line-chart";

export type AreaChartProps<T extends object> = Omit<LineChartProps<T>, "zero"> & {
  /** Stack the series so the top edge is their total. Missing values count as zero. */
  stacked?: boolean;
};

/** Same contract as LineChart. The y axis always starts at zero, because a fill is read by its height. */
export function AreaChart<T extends object>({ stacked = false, ...props }: AreaChartProps<T>) {
  return <SeriesChart {...props} area stacked={stacked} slot="area-chart" />;
}