# Interactive Area Chart

> A React SVG area chart with a crosshair that follows the pointer or arrow keys, showing the value and percent change against a dashed comparison line.

- Kind: Component (Charts)
- Docs: https://ui.minidev.pro/docs/interactive-area-chart
- Source (registry JSON with the full file): https://ui.minidev.pro/r/interactive-area-chart.json
- License: MIT. One file, yours to edit after install.

## When to use

Use it for one headline series over time with an optional "last period" line (revenue, signups). For a static area use AreaChart, for several lines use LineChart, and for a tiny inline trend use StatSparkline. Keyboard: Left and Right step through points, Home and End jump to the ends.

## Installation

### shadcn CLI (copies the source into your project)

```bash
npx shadcn@latest add @minidev/interactive-area-chart
```

Writes `components/ui/interactive-area-chart.tsx` plus the MiniDev files it is built from (area-chart) and installs its npm dependencies. Older CLI versions: `npx shadcn@latest add https://ui.minidev.pro/r/interactive-area-chart.json`.

### npm package

```bash
npm i minidev-ui-kit
```

Add the tokens to your global stylesheet once:

```css
@import "tailwindcss";
@import "minidev-ui-kit/styles.css";
@source "../node_modules/minidev-ui-kit";
```

Next.js also needs `transpilePackages: ["minidev-ui-kit"]` in next.config.

## Import

After the shadcn install:

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

From the npm package:

```tsx
import { InteractiveAreaChart } from "minidev-ui-kit/ui/interactive-area-chart"
```

## Usage

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

export function Example() {
  return (
    <InteractiveAreaChart />
  )
}
```

## Props

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `data` | `Point[]` | `SAMPLE` | no | Points in order, left to right. Defaults to twelve months of revenue. |
| `format` | `(n: number) => string` | `(n: number) => `$${n.toLocaleString()}k`` | no | Formats values in the header and for screen readers. |
| `label` | `string` | `"Revenue"` | no | Series name, shown in the header and legend and used as the accessible name. |
| `compareLabel` | `string` | `"Last year"` | no | Name of the comparison series. |
| `className` | `string` | - | no |  |

## Examples

### Against last year

Give every point a compare value to draw the dashed line and the change badge. Pass a format with a fixed locale.

```tsx
<InteractiveAreaChart
  label="Signups"
  compareLabel="Last year"
  format={(n) => n.toLocaleString("en-US")}
  data={[
    { label: "Jun", value: 1840, compare: 1420 },
    { label: "Jul", value: 2010, compare: 1510 },
    { label: "Aug", value: 1960, compare: 1630 },
    { label: "Sep", value: 2380, compare: 1700 },
    { label: "Oct", value: 2610, compare: 1880 },
    { label: "Nov", value: 2890, compare: 2050 },
  ]}
/>
```

### Single series

Leave out compare and only the main line and its value show. Focus the plot and use the arrow keys to read each point.

```tsx
<InteractiveAreaChart
  label="Payouts"
  format={(n) => `$${n.toLocaleString("en-US")}`}
  data={[
    { label: "Mon", value: 12400 },
    { label: "Tue", value: 9800 },
    { label: "Wed", value: 14100 },
    { label: "Thu", value: 13200 },
    { label: "Fri", value: 18600 },
  ]}
/>
```

## Keyboard interactions

| Key | Action |
| --- | --- |
| `Tab` | Moves focus to the plot. |
| `ArrowLeft` or `ArrowRight` | Moves the crosshair to the previous or next point. |
| `Home` or `End` | Moves the crosshair to the first or last point. |

## Accessibility

- The plot area is `role="slider"` with `aria-valuemin`, `aria-valuemax`, `aria-valuenow` (the point index) and `aria-valuetext` ("label: value").
- Its name is "label by N periods", such as "Revenue by 12 periods". The SVG, the dot and the x-axis labels are `aria-hidden`.
- The y-axis starts at 90% of the lowest value, not at zero, so small changes are visible. Say so near the chart if it matters.
- The dot's movement is a 100ms CSS transition, turned off with `motion-reduce:transition-none`.

## FAQ

### How do keyboard users read values in InteractiveAreaChart?

The plot is a focusable `role="slider"`. Left and Right arrows step through points, Home and End jump to the ends, and `aria-valuetext` announces the period and value, such as "Mar: $51k".

### Is the default format safe for server rendering?

Not fully. The default `format` is `$${n.toLocaleString()}k` with no locale, so a server and a browser in different locales can print different separators and cause a hydration warning. Pass your own `format` with a fixed locale, for example `(n) => n.toLocaleString("en-US")`.

### When does the dashed comparison line appear?

Only when every point has a `compare` value. The change badge in the header is separate: it shows for any point whose `compare` is set and not `0`, reading "+12.4% vs last year" with `compareLabel` in lower case.

## Rules for generating code

- Use semantic tokens only (bg, surface, sunken, border, fg, fg-muted, fg-subtle, ink, accent, success, warning, danger). Never raw hex or palette steps like blue-500.
- Shadows only from the set: shadow-xs, shadow-sm, shadow-raised, shadow-md, shadow-lg, shadow-overlay.
- Numbers use tabular-nums. Dark mode is the `dark` class on <html>; components never branch on theme.

## Dependencies

- Built from: [area-chart](https://ui.minidev.pro/docs/area-chart/md)

## Related

- [Area Chart](https://ui.minidev.pro/docs/area-chart/md): Dependency free SVG area chart for React with a smoothed line, dashed grid, gradient fill and an optional highlighted point. Strokes stay crisp at any size.
- [Line Chart](https://ui.minidev.pro/docs/line-chart/md): A multi series SVG line chart with smooth curves, a dashed hairline grid and dots on the last point of each line, colored from chart tokens. No library.
- [Stat Sparkline](https://ui.minidev.pro/docs/stat-sparkline/md): Metric card with a label, a large value, a signed delta and an edge-to-edge area sparkline that turns red when the trend is down. Built for React dashboards.
- [Scatter Chart](https://ui.minidev.pro/docs/scatter-chart/md): React scatter and bubble chart in plain SVG with rounded axis ticks, reference lines, hover that snaps to the nearest point and arrow-key point navigation.
- [Bar Chart](https://ui.minidev.pro/docs/bar-chart/md): Lightweight React bar chart with rounded bars, dashed gridlines and labels. Hovering a bar dims the rest and shows its value; the peak is highlighted first.
- [Chart Card](https://ui.minidev.pro/docs/chart-card/md): Card wrapper for charts with a title, optional description and a minimum height body. Pairs with the area, bar and donut charts in a React dashboard.

---

All 557 components: https://ui.minidev.pro/llms.txt (full text: https://ui.minidev.pro/llms-full.txt).
