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.
Revenue · Dec
$84k
+35.5% vs last yearHover or use arrow keys
Installation
npx shadcn@latest add @minidev/interactive-area-chart
MiniDev UI is in the shadcn registry directory, so the short form works with no setup. Older CLI versions can use the full URL: npx shadcn@latest add https://ui.minidev.pro/r/interactive-area-chart.json
Usage
import { InteractiveAreaChart } from "@/components/ui/interactive-area-chart"
export function Example() {
return (
<InteractiveAreaChart />
)
}
API reference
| Prop | Type | Default |
|---|---|---|
| dataPoints in order, left to right. Defaults to twelve months of revenue. | Point[] | SAMPLE |
| formatFormats values in the header and for screen readers. | (n: number) => string | (n: number) => `$${n.toLocaleString()}k` |
| labelSeries name, shown in the header and legend and used as the accessible name. | string | "Revenue" |
| compareLabelName of the comparison series. | string | "Last year" |
| className | string | - |
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.
Keyboard interactions
| Key | Action |
|---|---|
| Tab | Moves focus to the plot. |
| ArrowLeftorArrowRight | Moves the crosshair to the previous or next point. |
| HomeorEnd | Moves the crosshair to the first or last point. |
Accessibility
- The plot area is
role="slider"witharia-valuemin,aria-valuemax,aria-valuenow(the point index) andaria-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.
Frequently asked questions
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.
Dependencies
npm
Built from
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.
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.