

<Demo name="chart-area/demos/gradient" />

An area chart is a line chart whose fill carries meaning: distance from a baseline, or the span between two boundaries. Reach for it when the reader should compare magnitude or composition — not just because a filled chart looks stronger. When only the trend matters, use the [line chart](/docs/components/chart-line).

`AreaChart` takes your rows and the names of the fields to read. Colors, typography, grid, tooltip, and legend all come from your design system.

## Installation [#installation]

<InstallPrerequisite>
  Before adding components, init your project with your design system from the [Studio](/studio).
</InstallPrerequisite>

<CodeBlockTabs defaultValue="npm" groupId="package-manager">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="npm">
      npm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="pnpm">
      pnpm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="yarn">
      yarn
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="bun">
      bun
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="npm">
    ```bash
    npx shadcn@latest add @dotui/chart-area
    ```
  </CodeBlockTab>

  <CodeBlockTab value="pnpm">
    ```bash
    pnpm dlx shadcn@latest add @dotui/chart-area
    ```
  </CodeBlockTab>

  <CodeBlockTab value="yarn">
    ```bash
    yarn dlx shadcn@latest add @dotui/chart-area
    ```
  </CodeBlockTab>

  <CodeBlockTab value="bun">
    ```bash
    bunx shadcn@latest add @dotui/chart-area
    ```
  </CodeBlockTab>
</CodeBlockTabs>

It brings the `chart` core — the host, the palette, and the shared frame — along with it.

## Usage [#usage]

```tsx
import { AreaChart } from "@/components/ui/chart-area"
```

Point `x` at the category or time field and `y` at the value field. A chart is a figure, so `ariaLabel` is required.

```tsx
const data = [
  { month: "Jan", desktop: 186 },
  { month: "Feb", desktop: 305 },
  { month: "Mar", desktop: 237 },
]

export function Example() {
  return (
    <AreaChart
      data={data}
      x="month"
      y="desktop"
      labels={{ desktop: "Desktop" }}
      ariaLabel="Desktop visitors by month"
    />
  )
}
```

`data` is compared by identity, so define it outside your component — or memoize it. Every other prop is a flat scalar and can change freely.

## Data shape [#data-shape]

Two shapes work, and both draw the same chart.

**Wide** rows carry one column per series. Pass the columns as an array, and name them with `labels`:

```tsx
<AreaChart
  data={data}
  x="month"
  y={["desktop", "mobile"]}
  labels={{ desktop: "Desktop", mobile: "Mobile" }}
  ariaLabel="Visitors by device"
/>
```

**Long** rows carry one row per series per x value, with the series key in its own field. Pass that field as `series`, and set `seriesOrder` to lead the color slots and the legend — series the data carries but `seriesOrder` omits follow in the order they first appear:

```tsx
<AreaChart
  data={data}
  x="month"
  y="visitors"
  series="channel"
  seriesOrder={["paid_social", "organic_search"]}
  labels={{ organic_search: "Organic search", paid_social: "Paid social" }}
  ariaLabel="Visitors by acquisition channel"
/>
```

Series take colors from `--chart-1` through `--chart-8` in order. A `null` value leaves a gap rather than dropping to zero.

## Stacking [#stacking]

`stacked` stacks the series on one another, in `seriesOrder`; the tooltip still reports each band's own value.

```tsx
<AreaChart
  data={data}
  x="month"
  y={["desktop", "mobile", "other"]}
  labels={{ desktop: "Desktop", mobile: "Mobile", other: "Other" }}
  stacked
  ariaLabel="Visitors by device, stacked"
/>
```

Positive values stack up from zero and negative values down from it, so a mixed-sign group never overlaps itself. `stacked="normalize"` divides each band by its own x-group total for a 100% stack — format the value axis as a percentage with `formatY`.

## Shape [#shape]

`curve` sets the interpolation: `natural` (the default), `monotone`, `linear`, or `step`. `fill` takes an opacity, or `'gradient'` for a fade toward the baseline. `strokeWidth` and `points` control the upper edge.

Interpolation only changes the path drawn between observations. It does not smooth the data or create evidence between samples.

## Annotations [#annotations]

`marks` and `marksBefore` accept raw [TanStack Charts](https://tanstack.com/charts) mark layers, painted over and under the areas on the same scales. Use them for a target rule, a highlighted band, or end labels.

```tsx
import { ruleY } from "@tanstack/charts/rule"

const target = ruleY([200], { strokeDasharray: "4 4" })
```

```tsx
<AreaChart
  data={data}
  x="month"
  y="desktop"
  marks={[target]}
  ariaLabel="Desktop visitors against target"
/>
```

## Accessibility [#accessibility]

* `ariaLabel` is required and names the figure; add `ariaDescription` when the takeaway needs a sentence.
* The chart surface is in the tab order. Arrow keys move between points, `Home` and `End` jump to the first and last, `Enter` and Space pin the tooltip, and `Escape` dismisses it.
* Color alone never carries the distinction — the legend, tooltip, and axis labels all name the series.
* `tooltip={false}` keeps the focus stops but removes their live region, so screen readers land on silent points. Turn it off only for a decorative chart.

## Examples [#examples]

<Examples>
  <Example name="chart-area/demos/default" title="Default" />

  <Example name="chart-area/demos/legend" title="Multiple Series" />

  <Example name="chart-area/demos/gradient" title="Gradient" />

  <Example name="chart-area/demos/stacked" title="Stacked" />

  <Example name="chart-area/demos/stacked-expand" title="Stacked Expanded" />

  <Example name="chart-area/demos/labels" title="Long Format Labels" />

  <Example name="chart-area/demos/axes" title="Axis Formatting" />

  <Example name="chart-area/demos/linear" title="Linear" />

  <Example name="chart-area/demos/step" title="Step" />

  <Example name="chart-area/demos/interactive" title="Interactive" />
</Examples>

## API Reference [#api-reference]

### AreaChart [#areachart]

<Reference name="area-chart" />
