# Area chart

Stacked or layered areas with a crosshair, soft edges and an entrance sweep.

Section: Charts / Cartesian
Page: https://ui.heyramzi.com/components/area-chart
Import path: `@heyramzi/ui/charts`

## Import

```ts
import { AreaChart } from "@heyramzi/ui/charts";
```

## Usage

```svelte
<AreaChart
  data={[{ month: "Jan", revenue: 3200, cost: 1800 }]}
  xKey="month"
  series={[
    { key: "revenue", label: "Revenue", color: "var(--chart-1)" },
    { key: "cost", label: "Cost", color: "var(--chart-3)" },
  ]}
  height={260}
/>
```

## Examples

### Two value axes

Set axis: "right" on a series to give it its own scale on the right. Both axes share one grid, each axis takes its series' colour, and the tooltip shows every series for the hovered day.

```svelte
<script lang="ts">
	import { AreaChart } from "@heyramzi/ui/charts";

	// Four weeks of search traffic: impressions run about 40 times clicks.
	const clicks = [
		112, 128, 141, 136, 98, 87, 119, 133, 152, 147, 158, 104, 96, 131, 144, 139, 161, 155, 109, 101,
		138, 149, 157, 166, 151, 112, 107, 143,
	];
	const impressions = [
		4410, 4890, 5230, 5120, 3980, 3710, 4620, 5010, 5540, 5390, 5810, 4170, 3920, 4980, 5360, 5240,
		5920, 5710, 4300, 4060, 5150, 5480, 5770, 6030, 5600, 4420, 4210, 5330,
	];
	const start = Date.UTC(2026, 9, 6);
	const data = clicks.map((c, i) => ({
		date: new Date(start + i * 86_400_000),
		clicks: c,
		impressions: impressions[i],
	}));
	const sum = (xs: number[]) => xs.reduce((a, b) => a + b, 0);
</script>

<AreaChart
	{data}
	xKey="date"
	series={[
		{ key: "clicks", label: "Clicks", color: "var(--chart-3)" },
		{ key: "impressions", label: "Impressions", color: "var(--chart-4)", axis: "right" },
	]}
	resting={{
		values: { clicks: sum(clicks), impressions: sum(impressions) },
		label: "Last 28 days",
	}}
	formatValue={(v) => Math.round(v).toLocaleString("en-US")}
	formatX={(v) =>
		(v as Date).toLocaleDateString("en-US", { month: "short", day: "numeric", timeZone: "UTC" })}
	height={240}
	label="Search clicks and impressions"
/>
```

## Demo

```svelte
<script lang="ts">
	import { AreaChart } from "@heyramzi/ui/charts";

	const data = [
		{ month: "Jan", revenue: 3200, cost: 1800 },
		{ month: "Feb", revenue: 4100, cost: 2100 },
		{ month: "Mar", revenue: 3800, cost: 2400 },
		{ month: "Apr", revenue: 5300, cost: 2600 },
		{ month: "May", revenue: 6100, cost: 3000 },
		{ month: "Jun", revenue: 7200, cost: 3300 },
		{ month: "Jul", revenue: 6900, cost: 3100 },
		{ month: "Aug", revenue: 8100, cost: 3600 },
	];
</script>

<AreaChart
	{data}
	xKey="month"
	series={[
		{ key: "revenue", label: "Revenue", color: "var(--chart-1)" },
		{ key: "cost", label: "Cost", color: "var(--chart-3)" },
	]}
	formatValue={(v) => `$${v.toLocaleString()}`}
	height={260}
/>
```

## API

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `data` | `TData[]` |  | required |
| `xKey` | `keyof TData & string` |  | required |
| `yKey` | `keyof TData & string` |  |  |
| `series` | `Series[]` |  |  |
| `color` | `string` | `"var(--chart-series-1)"` |  |
| `height` | `number` | `240` |  |
| `stacked` | `boolean` | `false` |  |
| `smooth` | `boolean` | `true` |  |
| `edgeFade` | `boolean \| number` | `true` | Softens the left and right ends of the filled area instead of cutting them off at the plot edge. |
| `formatValue` | `(v: number) => string` | `(v) => v.toLocaleString()` |  |
| `formatX` | `(v: unknown) => string` | `(v) => String(v)` |  |
| `xTicks` | `number` | `6` |  |
| `reference` | `ChartReference` |  | A target drawn across the plot, like the deal a cost runs up to. |
| `resting` | `{ value?: number; values?: Partial<Record<keyof TData & string, number>>; label: string; }` |  | The headline while no point is hovered, like a period total. Defaults to the last point. `values`, keyed by series, shows one figure per series side by side in its colour, so it also reads as the legend. |
| `smoothing` | `Smoothing` |  | Smooths the drawn line by the window shown; the resting figure stays the caller's total. |
| `label` | `string` | `"Area chart"` | The chart's accessible name. Its data range and values are read after it. |
| `class` | `string` |  |  |
