# Area Chart

Trends over time, stacked or overlapping, with optional gradient fills.

Page: https://sui.draco.dev/docs/charts/area-chart

### Example: area-chart-demo

```tsx
"use client";
import { AreaChart, chartLabelsZhCN } from "@workspace/ui/charts/area-chart";
import type { ExampleProps } from "../types";

const months = [
  { month: "Jan", desktop: 186, mobile: 80 },
  { month: "Feb", desktop: 305, mobile: 200 },
  { month: "Mar", desktop: 237, mobile: 120 },
  { month: "Apr", desktop: 73, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "Jun", desktop: 214, mobile: 140 },
];

function deviceConfig(chinese: boolean) {
  return {
    desktop: { label: chinese ? "桌面端" : "Desktop", color: "var(--chart-1)" },
    mobile: { label: chinese ? "移动端" : "Mobile", color: "var(--chart-2)" },
  };
}

export default function Example({ locale }: ExampleProps) {
  const chinese = locale === "zh-CN";
  return (
    <AreaChart
      data={months}
      config={deviceConfig(chinese)}
      index="month"
      gradient
      showLegend
      aria-label={chinese ? "近六个月访问量" : "Visitors over six months"}
      labels={chinese ? chartLabelsZhCN : undefined}
    />
  );
}
```

## Installation

```bash
npx shadcn@latest add @sui/area-chart
```

With pnpm, Yarn or Bun, use `pnpm dlx`, `yarn dlx` or `bunx --bun` in place of `npx`, and `pnpm add`, `yarn add` or `bun add` in place of `npm install`.

Install with the shadcn CLI or use the shared `@workspace/ui` package. Follow the [installation guide](/docs/installation) to configure the registry, load styles, and choose import aliases.

## Usage

```tsx
import { AreaChart } from "@workspace/ui/charts/area-chart";

<AreaChart data={data} config={config} index="month" gradient />;
```

## Stacked

Set `stacked` to add series together. `curve` changes the line shape.

### Example: area-chart-stacked

```tsx
"use client";
import { AreaChart, chartLabelsZhCN } from "@workspace/ui/charts/area-chart";
import type { ExampleProps } from "../types";

const months = [
  { month: "Jan", desktop: 186, mobile: 80 },
  { month: "Feb", desktop: 305, mobile: 200 },
  { month: "Mar", desktop: 237, mobile: 120 },
  { month: "Apr", desktop: 73, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "Jun", desktop: 214, mobile: 140 },
];

function deviceConfig(chinese: boolean) {
  return {
    desktop: { label: chinese ? "桌面端" : "Desktop", color: "var(--chart-1)" },
    mobile: { label: chinese ? "移动端" : "Mobile", color: "var(--chart-2)" },
  };
}

export default function Example({ locale }: ExampleProps) {
  const chinese = locale === "zh-CN";
  return (
    <AreaChart
      data={months}
      config={deviceConfig(chinese)}
      index="month"
      stacked
      curve="step"
      showYAxis
      labels={chinese ? chartLabelsZhCN : undefined}
    />
  );
}
```

## Loading and empty states

`loading` shows a skeleton; an empty `data` array shows the `empty` label.

### Example: area-chart-states

```tsx
"use client";
import { AreaChart, chartLabelsZhCN } from "@workspace/ui/charts/area-chart";
import type { ExampleProps } from "../types";

const months = [
  { month: "Jan", desktop: 186, mobile: 80 },
  { month: "Feb", desktop: 305, mobile: 200 },
  { month: "Mar", desktop: 237, mobile: 120 },
  { month: "Apr", desktop: 73, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "Jun", desktop: 214, mobile: 140 },
];

function deviceConfig(chinese: boolean) {
  return {
    desktop: { label: chinese ? "桌面端" : "Desktop", color: "var(--chart-1)" },
    mobile: { label: chinese ? "移动端" : "Mobile", color: "var(--chart-2)" },
  };
}

export default function Example({ locale }: ExampleProps) {
  const chinese = locale === "zh-CN";
  return (
    <div className="grid w-full gap-4 sm:grid-cols-2">
      <AreaChart
        data={months}
        config={deviceConfig(chinese)}
        index="month"
        loading
        labels={chinese ? chartLabelsZhCN : undefined}
      />
      <AreaChart
        data={[]}
        config={deviceConfig(chinese)}
        index="month"
        labels={chinese ? chartLabelsZhCN : undefined}
      />
    </div>
  );
}
```

## Customize

The wrapper covers common cases. For more control, pass Recharts elements as `children`, or compose your own chart with the [Chart](/docs/charts/chart) primitives.

## API reference

| Prop | Type | Default / behavior |
| --- | --- | --- |
| `stacked` | `boolean` | `false`. |
| `curve` | `"linear" \| "natural" \| "monotone" \| "step"` | `"natural"`. |
| `gradient` | `boolean` | `false`. Fades each area toward the axis. |
| `index` | `string` | Required. The category-axis key. |
| `categories` | `readonly string[]` | Every key in `config`. |
| `showGrid` / `showXAxis` / `showYAxis` | `boolean` | Grid and x axis on; y axis varies by chart. |
| `dir` | `"ltr" \| "rtl"` | `"ltr"`. Mirrors the axes. |
| `data` | `readonly Record<string, unknown>[]` | Required rows. |
| `config` | `ChartConfig` | Required. Labels, colors and icons by key; series without a color use `--chart-1` to `--chart-5`. |
| `valueFormatter` | `(value: number) => string` | `toLocaleString`. Formats axes, tooltip and the screen-reader table; build one with `numberFormatter`. |
| `showLegend` | `boolean` | `false`. Legend buttons show and hide series. |
| `showTooltip` | `boolean` | `true`. |
| `loading` | `boolean` | `false`. Shows a skeleton. |
| `labels` | `Partial<ChartLabels>` | English labels; pass `chartLabelsZhCN` for Chinese. |
| `aria-label` | `string` | Names the figure and captions its data table. |
| `className` | `string` | Sizes the chart; defaults to a 16:9 box. |
| `children` | `ReactNode` | Extra Recharts elements, such as `ReferenceLine`. |

The module also exports `AreaChartProps`, `numberFormatter`, and the label presets `chartLabels` and `chartLabelsZhCN`. Screen readers get a hidden data table while the drawing itself is hidden from assistive technology, and animation is off when reduced motion is requested.
