shadcn.io is not affiliated with official shadcn/ui
About
This is the dashboard chart: a long daily series where the reader picks the window. Use it when one view has to serve both the quarter and the last week. For two series people compare one at a time, the Interactive Bar Chart switches between them instead.
Desktop and mobile stack as smooth curves with gradient fills, under date labels spaced so they don't collide. A select in the header filters to the last 90, 30 or 7 days, the tooltip shows the date, and a legend sits under the plot.
Installation
Usage
import { ChartAreaInteractive } from "@/components/charts/chart-area-interactive";<ChartAreaInteractive />Customize
useState("90d")holds the range;chartData.filterkeeps the days after June 30, 2024 minus 90, 30 or 7.<XAxis dataKey="date" minTickGap={32}>skips crowded labels, and itstickFormatterprintsApr 10.labelFormatteronChartTooltipContentformats the hovered date the same way.- The gradients are
<linearGradient>s in<defs>; the legend is<ChartLegend content={<ChartLegendContent />} />. ChartContainerhasaspect-auto h-[250px] w-full, so the height stays fixed as the card widens.
FAQ
How does the range filter work?
The rows run from April 1 to June 30, 2024. The select's value (90d, 30d or 7d) sets how many days to count back from June 30, and only the rows from that date on reach the chart. With live data, count back from today or ask your API for the range.
Does it animate when the range changes?
Yes: Recharts animates the areas to the new data. Set isAnimationActive={false} on each <Area> to turn it off.
Why does the select disappear on phones?
Its trigger has hidden sm:flex, as in shadcn/ui's original, so below the sm breakpoint the chart shows the full 90 days. Remove hidden to keep the select on small screens.
How do I plot my own dates?
Give each row an ISO date (2024-04-01) and the two values. The label formatters parse it with new Date(), which reads a day-only date as midnight UTC: format with timeZone: "UTC" or readers west of UTC see the day before.
API Reference
ChartContainer
configChartConfig
Each series by its data key: its label, an icon, and a color (or a * theme color per light and dark), read by the tooltip and legend and set * as --color-<key>.
initialDimension?{ height: number; width: number; }
The size it renders at before it's measured, so the first paint isn't * empty.
- Type
{ height: number; width: number; }- Default
INITIAL_DIMENSION
className?string
Merged with the part's classes.
ChartLegend
ChartLegendContent
<div>
hideIcon?boolean
Hides each series' icon (from config), leaving its color swatch.
- Default
false
nameKey?string
The key in each legend item's data to look its label up by in config. * Defaults to the item's dataKey.
className?string
Merged with the part's classes.
ChartStyle
<style>
configChartConfig
The chart config whose colors it writes as --color-<key> variables.
idstring
The element's id.
ChartTooltip
ChartTooltipContent
<div>
hideIndicator?boolean
Hides each item's color indicator.
- Default
false
hideLabel?boolean
Hides the tooltip's label, the hovered point's.
- Default
false
indicator?"dashed" | "dot" | "line"
The color indicator's shape: a dot, a line or dashed.
- Type
"dashed" | "dot" | "line"- Default
"dot"
labelFormatter?(label: any, payload: TooltipPayload) → React.ReactNode
Formats the tooltip's label; its value is untyped, as in recharts 3.8.
- Type
(label: any, payload: TooltipPayload) → React.ReactNode- Parameters
label– anypayload– TooltipPayload- Returns
React.ReactNode
labelKey?string
The key in the data to read the label from, looked up in config.
nameKey?string
The key in each item's data to look its name up by in config.
className?string
Merged with the part's classes.
Related
Interactive Bar Chart
Bar chartsThree months of daily bars, switched between two series.
Interactive Line Chart
Line chartsThree months of daily values, switched between two series.
Gradient Area Chart
Area chartsAreas filled with a vertical gradient that fades to the axis.
Interactive Pie Chart
Pie chartsA donut whose active month is picked from a select.
A tooltip whose label is formatted as a full date.
Area Chart with Legend
Area chartsStacked areas with a legend naming each series.