Chart
Composable chart primitives built on Recharts: a themed container, tooltip, and legend that pick up your shadcn chart colors.
Installation
Bash
Usage
Examples
Line chart
API reference
A thin wrapper over Recharts v3 (pinned to
^3.10.1) — charts compose from recharts primitives (BarChart,
LineChart, CartesianGrid, XAxis, and the rest) inside a
ChartContainer. We wrap the container, tooltip, and legend — not every
chart type — so any recharts component works inside. v2 snippets you find
online need porting to the v3 API.
ChartContainertakes aconfig: ChartConfigand renders recharts’ResponsiveContainerinside adata-chart-scopeddiv, plus an injected<style>tag (ChartStyle) that defines the series’ CSS variables.ChartConfigmaps each series key to alabel/iconand either a singlecoloror a per-themetheme: { light, dark }pair.- Series colors resolve as
var(--color-<key>)inside the container, scoped to that chart’sdata-chartid. Dark values apply under the.dark [data-chart=…]selector (the shadcn consumer convention). ChartTooltip/ChartLegendare direct re-exports of recharts’Tooltip/Legend;ChartTooltipContentandChartLegendContentare our styledcontentrenderers, wired up ascontent={<ChartTooltipContent />}.ChartTooltipContentacceptshideLabel,hideIndicator,indicator="line" | "dot" | "dashed",nameKey, andlabelKey, on top of recharts’ own tooltip content props.ChartLegendContentacceptshideIconandnameKey, on top of recharts’payload/verticalAlign.
v3 gotchas you’ll hit if you’ve used recharts v2:
- Type custom tooltip content against the root-exported
TooltipContentProps— notReact.ComponentProps<typeof Tooltip>, which is the v2 idiom and does not describe the v3 content-renderer props. - Legend items sort alphabetically by default; pass
itemSorter={null}onLegendto preserve series order. accessibilityLayerdefaults totruein v3 — you no longer need to pass it yourself.