Values over time as filled areas: one series, several, or stacked into a total, with a dashed one for a comparison. Plain SVG.
$ pnpm dlx shadcn@latest add https://dashral.com/r/area-chart.jsonInstallation
$ pnpm dlx shadcn@latest add https://dashral.com/r/area-chart.jsonAdds the component, the components it builds on, its npm packages and the theme tokens it uses. Using Dashral often? Add the registry to components.json once:
{
"registries": {
"@dashral": "https://dashral.com/r/{name}.json"
}
}Then add components by name:
$ pnpm dlx shadcn@latest add @dashral/area-chartUsage
import { AreaChart } from "@/components/dashral/area-chart"
<AreaChart
data={[
{ month: "Jan", revenue: 4200, costs: 2400 },
{ month: "Feb", revenue: 5100, costs: 2600 },
{ month: "Mar", revenue: 6300, costs: 2900 },
]}
index="month"
series={[
{ key: "revenue", label: "Revenue" },
{ key: "costs", label: "Costs" },
]}
formatOptions={{ style: "currency", currency: "USD" }}
aria-label="Revenue and costs by month"
/>Examples
API reference
AreaChart
Also takes every prop of <div>(opens in a new tab).
| Prop | Type | Default |
|---|---|---|
data | Record<string, string | number>[]The rows, in order along the x axis. Required. | — |
index | stringThe key for the x axis: a label, or a timestamp or ISO date with timeFormat. Required. | — |
series | { key, label, color?, dashed? }[]What to draw, in order; colors default to --chart-1 … --chart-5. Required. | — |
stacked | booleanPuts the series on one another, so the top line is their total. | false |
curve | "smooth" | "linear" | "step"Smooth never bends past a value it didn't have. | "smooth" |
height | numberIn pixels, axes included; the width follows the container. | 260 |
formatOptions | Intl.NumberFormatOptionsHow values are written in the tooltip, e.g. { style: "currency", currency: "USD" }; the axis writes them compactly. | — |
timeFormat | Intl.DateTimeFormatOptionsReads the index as dates and writes them like this. | — |
showLegend | boolean | more than one series |
showGrid | booleanDashed lines at the axis values. | true |
showYAxis | booleanThe values along the left. | true |
locale | string | the LocaleProvider's |
aria-label | stringWhat the chart shows, e.g. “Revenue by month”. | "Trend from … to …" |
classNames | { legend, tooltip } | — |
Keyboard
| Keys | Action |
|---|---|
| Tab | Focus the chart |
| ←or→ | Read the previous or next point |
| HomeorEnd | The first or last point |
| Esc | Stop reading |
Accessibility
- A group named by your label (by default, how the first series went); the point you move to with the arrow keys is read out with every series' value.
- The x axis runs left to right in every language, as on most charts; the legend and tooltip follow the page's direction.
- The tooltip lists every series by name, so nothing depends on telling colors apart.
Motion
- Draws in from the left when it first shows; new data moves the areas to their new shape (in browsers that animate SVG paths). Instant with reduced motion.