> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Area Chart

Plot one series of points as a line with the area below it filled, and a touch tooltip, pan and zoom, and dark mode built in.


## Installation

```bash
npx @blotch/dolan add area-chart
```

```typescript
import { UiAreaChart } from '../components/ui/area-chart';
```

This also adds [Chart](/dolan/chart.md), which draws the preset, and installs the npm packages `@tanstack/charts`, `d3-shape` and `@types/d3-shape`.

## Usage

```typescript
import { Component } from '@angular/core';
import { UiAreaChart } from '../components/ui/area-chart';

@Component({
  selector: 'app-visitors',
  imports: [UiAreaChart],
  template: `<ui-area-chart [data]="visitors" label="Daily visitors" />`,
})
export class Visitors {
  protected readonly visitors = [
    { x: 1, y: 12 },
    { x: 2, y: 19 },
    { x: 3, y: 15 },
    { x: 4, y: 25 },
  ];
}
```

- `data` is an array of `{ x, y }` points, both numbers. The axes fit rounded ranges to the data, and the fill reaches down to `y = 0`.
- Touch the chart to see a point's values in a tooltip. Tap to pin it.
- Set `label` so a screen reader can say what the chart shows.

## Customize

### Colors

`color` sets the line, the dots and the fill. `fillOpacity` sets how solid the fill is, from `0` to `1` (default `0.2`). A theme color such as `var(--chart-2)` switches with [dark mode](/dolan/chart.md#theming-and-dark-mode). A fixed color stays the same.

```angular-html
<ui-area-chart [data]="downloads" color="var(--chart-2)" [fillOpacity]="0.3" />
```

### Shape

`smooth` curves the line and the fill through the points. The curve is monotone (d3's `curveMonotoneX`), so the fill never bulges past a peak.

`baseline` is the y value the fill reaches to (default `0`), and the y axis always includes it. Where the data dips below the baseline, the fill reaches up to it instead.

```angular-html
<ui-area-chart [data]="delta" smooth [baseline]="0" />
```

`strokeWidth` and `dotRadius` are in px. Set `showDots` to `false` to hide the dots.

### Axes and range

`xAxisLabel` and `yAxisLabel` add axis titles. Horizontal gridlines are on by default: `showGrid` turns them off, and `showXGrid` adds vertical ones.

```angular-html
<ui-area-chart
  [data]="visitors"
  xAxisLabel="Day"
  yAxisLabel="Visitors"
  [yMax]="40"
/>
```

- `xMin`, `xMax`, `yMin` and `yMax` fix a bound instead of fitting the data.
- `xTickFormat` and `yTickFormat` turn tick values into labels.
- `tickCount` sets roughly how many ticks each axis gets. The axis picks round values near it.

### Padding

`padding` insets the plot, each side as a fraction (`0` to `1`) of its size.

```angular-html
<ui-area-chart [data]="visitors" [padding]="{ left: 0.05, right: 0.05 }" />
```

### Size

The chart fills its container's width and is 200px tall. Set `height` for another height and `width` for a fixed width, both in px. Use `height` rather than a height class, because the preset always sets a height.

```angular-html
<ui-area-chart [data]="visitors" [height]="160" />
```

## Interaction

### Taps

`pointTap` emits the tapped `{ x, y }` point. A tap on empty space emits nothing. Set `tooltip` to `false` to turn the tooltip off.

```angular-html
<ui-area-chart [data]="visitors" (pointTap)="selected.set($event)" />
```

`pointTap` fires inside the touch, so it can change signals or navigate, as a tap handler can.

### Pan and zoom

Set `zoomable` to let users drag to pan, with **+**, **−** and **1:1** buttons. `zoomAxes` limits it to one axis.

```angular-html
<ui-area-chart [data]="visitors" zoomable zoomAxes="x" />
```

To zoom from your own controls, set `showZoomControls` to `false` and call `zoomIn()`, `zoomOut()` or `resetZoom()` on the component. See [Pan and zoom](/dolan/chart.md#pan-and-zoom) for how it behaves.

## API

### UiAreaChart

| Input              | Type                            | Default                    | Description                                            |
| ------------------ | ------------------------------- | -------------------------- | ------------------------------------------------------ |
| `data`             | `readonly XYDatum[]`            | Required                   | Points to plot, each `{ x, y }`.                       |
| `color`            | `string`                        | `'var(--primary)'`         | Line, dot and fill color (any CSS color).              |
| `fillOpacity`      | `number`                        | `0.2`                      | Opacity of the fill, `0`–`1`.                          |
| `baseline`         | `number`                        | `0`                        | The y value the fill reaches to. Always kept in view.  |
| `strokeWidth`      | `number`                        | `2`                        | Line thickness in px.                                  |
| `dotRadius`        | `number`                        | `3`                        | Dot radius in px. `0` hides the dots.                  |
| `showDots`         | `boolean`                       | `true`                     | Draw a dot at each point.                              |
| `smooth`           | `boolean`                       | `false`                    | Draw a monotone curve instead of straight segments.    |
| `width`            | `number`                        | _fills container_          | Fixed width in px.                                     |
| `height`           | `number`                        | `200`                      | Height in px.                                          |
| `tickCount`        | `number`                        | `5`                        | Target number of ticks per axis.                       |
| `showGrid`         | `boolean`                       | `true`                     | Horizontal gridlines at the y ticks.                   |
| `showXGrid`        | `boolean`                       | `false`                    | Vertical gridlines at the x ticks.                     |
| `xAxisLabel`       | `string`                        | `''`                       | X-axis title.                                          |
| `yAxisLabel`       | `string`                        | `''`                       | Y-axis title.                                          |
| `padding`          | `ChartPadding`                  | `{}`                       | Inner inset, each side a `0`–`1` fraction of the plot. |
| `xMin`             | `number`                        | _fits the data_            | Fixed x-axis lower bound.                              |
| `xMax`             | `number`                        | _fits the data_            | Fixed x-axis upper bound.                              |
| `yMin`             | `number`                        | _fits the data_            | Fixed y-axis lower bound.                              |
| `yMax`             | `number`                        | _fits the data_            | Fixed y-axis upper bound.                              |
| `xTickFormat`      | `(value: number) => string`     | _automatic_                | Formats x-axis tick labels.                            |
| `yTickFormat`      | `(value: number) => string`     | _automatic_                | Formats y-axis tick labels.                            |
| `tooltip`          | `boolean`                       | `true`                     | Show a tooltip for the touched point. A tap pins it.   |
| `label`            | `string`                        | `'Chart'`                  | What a screen reader announces for the chart.          |
| `colorScheme`      | `'light' \| 'dark' \| 'system'` | _from `provideChartTheme`_ | Which color table the marks use.                       |
| `zoomable`         | `boolean`                       | `false`                    | Drag to pan, with zoom buttons.                        |
| `zoomAxes`         | `'x' \| 'y' \| 'xy'`            | `'xy'`                     | Which axes pan and zoom.                               |
| `showZoomControls` | `boolean`                       | `true`                     | Show the +/−/1:1 buttons when zoomable.                |
| `minZoom`          | `number`                        | `1`                        | Smallest zoom. `1` shows all the data.                 |
| `maxZoom`          | `number`                        | `8`                        | Largest zoom.                                          |
| `zoomStep`         | `number`                        | `1.4`                      | Zoom factor per button press or method call.           |
| `class`            | `string`                        | `''`                       | Extra Tailwind classes for the chart's root view.      |

| Output     | Type      | Description                |
| ---------- | --------- | -------------------------- |
| `pointTap` | `XYDatum` | The point a tap landed on. |

| Method        | Description               |
| ------------- | ------------------------- |
| `zoomIn()`    | Zooms in by `zoomStep`.   |
| `zoomOut()`   | Zooms out by `zoomStep`.  |
| `resetZoom()` | Shows all the data again. |

`XYDatum` is `{ x: number; y: number }`. `ChartPadding` is `{ top?, right?, bottom?, left? }`, each a fraction (`0`–`1`) of the plot's size, with omitted sides `0`. Both are exported from `../components/ui/chart`.

### areaChartDefinition

```typescript
function areaChartDefinition(options: AreaChartOptions): ChartDefinition;
```

Returns the [TanStack Charts](https://tanstack.com/charts) definition `<ui-area-chart>` renders: an `areaY` fill down to the baseline, a `lineY` on top, and optional dots. The options are the inputs that shape the chart, with the same defaults: `data`, `color`, `fillOpacity`, `baseline`, `strokeWidth`, `dotRadius`, `showDots`, `smooth`, `tickCount`, `showGrid`, `showXGrid`, `xAxisLabel`, `yAxisLabel`, `padding`, `xMin`, `xMax`, `yMin`, `yMax`, `xTickFormat`, `yTickFormat` and `tooltip`. Size, label, color scheme and zoom are inputs of `<ui-chart>` instead.

Start from it to add marks of your own, such as a goal line, and render the result with [`<ui-chart>`](/dolan/chart.md). For several or stacked areas, build a definition with `areaY` instead.

```typescript
import { defineChart, ruleY } from '@tanstack/charts/universal';
import { areaChartDefinition } from '../components/ui/area-chart';

const base = areaChartDefinition({ data: visitors, smooth: true });

protected readonly withGoal = defineChart({
  ...base,
  marks: [...base.marks, ruleY([20], { stroke: 'var(--muted-foreground)' })],
});
```

## Related

- [Chart](/dolan/chart.md): several or stacked areas, and other marks
- [Line Chart](/dolan/line-chart.md): the line without the fill
- [Bar Chart](/dolan/bar-chart.md): values as bars
