If you have seen polished, theme-aware charts in a shadcn/ui project, you have already seen Recharts at work. The Recharts shadcn combination is popular because it pairs Recharts' drawing engine with shadcn's design tokens — without hiding the Recharts API.
shadcn/ui uses Recharts under the hood
The shadcn/ui chart documentation states plainly that it uses Recharts under the hood and does not wrap it. You build charts with normal Recharts components such as BarChart, Bar and XAxis, and only bring in shadcn's helper components where they add value. Because nothing is abstracted away, you can follow Recharts' own upgrade path when a new version is released.
Adding the chart component
Like other shadcn/ui components, the chart helpers are copied into your project with the CLI:
npx shadcn@latest add chart
This adds a chart component file to your UI folder and installs Recharts as a dependency. The code is yours to read and modify.
The pieces shadcn adds
- ChartContainer – a wrapper that applies sizing and turns your chart config into CSS variables.
- ChartConfig – an object mapping each data key to a label and colour.
- ChartTooltip / ChartTooltipContent – a styled tooltip that reads labels and colours from the config.
- ChartLegend / ChartLegendContent – a matching legend.
A minimal example
"use client";
import { Bar, BarChart, CartesianGrid, XAxis } from "recharts";
import {
ChartContainer, ChartTooltip, ChartTooltipContent, type ChartConfig,
} from "@/components/ui/chart";
const chartData = [
{ month: "January", desktop: 186, mobile: 80 },
{ month: "February", desktop: 305, mobile: 200 },
{ month: "March", desktop: 237, mobile: 120 },
];
const chartConfig = {
desktop: { label: "Desktop", color: "var(--chart-1)" },
mobile: { label: "Mobile", color: "var(--chart-2)" },
} satisfies ChartConfig;
export function VisitorsChart() {
return (
<ChartContainer config={chartConfig} className="min-h-[200px] w-full">
<BarChart accessibilityLayer data={chartData}>
<CartesianGrid vertical={false} />
<XAxis dataKey="month" tickLine={false} axisLine={false} />
<ChartTooltip content={<ChartTooltipContent />} />
<Bar dataKey="desktop" fill="var(--color-desktop)" radius={4} />
<Bar dataKey="mobile" fill="var(--color-mobile)" radius={4} />
</BarChart>
</ChartContainer>
);
}
Notice that everything inside ChartContainer is plain Recharts. The --color-desktop variable is generated from the config, which is how the chart follows your theme.
Theming with chart tokens
shadcn themes define a set of chart colour variables (--chart-1 to --chart-5) in your global CSS. Point your config at those tokens and every chart picks up the palette, including in dark mode if your theme defines one.
When updating older chart code to Recharts v3, the shadcn docs advise referencing tokens as var(--chart-1) instead of hsl(var(--chart-1)).
Why ChartContainer needs a height
Just like Recharts' own ResponsiveContainer, the shadcn container sizes the chart from its box. Give it a minimum height (for example min-h-[200px]) or an aspect ratio, otherwise it can render at zero height. Our troubleshooting guide covers this in detail.
When to use plain Recharts instead
shadcn's helpers shine when your app already uses shadcn/ui and Tailwind. If your project does not, you lose nothing by using Recharts directly — the drawing engine is identical. Start with the React tutorial or the examples guide and style charts with props and CSS.
Further considerations
- shadcn/ui charts are Recharts charts with a thin, copy-in styling layer.
- ChartConfig maps your data keys to labels and theme colours.
- You can always drop down to any Recharts prop or component.
Understand the two layers of the chart
shadcn/ui offers chart components that work with Recharts rather than replacing its charting model. Recharts handles shapes, axes, Cartesian data and interactions; the surrounding UI components provide convenient conventions for colour, labelling and tooltip presentation. This division is useful for design systems because visual consistency can be managed at the application level while the chart continues to use familiar Recharts primitives. Understanding which layer owns a decision makes customisation much less confusing.
Begin with a basic chart before applying a complex theme. Define a small data array, configure readable labels and give ChartContainer a definite height or aspect ratio. Then add the desired Recharts components and the tooltip treatment supplied by the UI layer. When something breaks, inspect the level responsible: a missing series is often a data-key problem, while a zero-height plot usually points to layout. Treating those as separate questions is faster than modifying colours, data and rendering settings simultaneously.
Design a coherent colour system
A dashboard needs more than an attractive palette. Assign chart colours according to meaning and use them consistently across components: the same metric should not change hue from one card to the next without a reason. shadcn/ui’s chart configuration can express descriptive labels and series colours, while application-level CSS variables allow visual choices to remain centrally managed. Use tokens in the format expected by the version of the chart components your project actually contains.
When a product supports light and dark themes, review contrast in both rather than relying on automatic inversion. A colour that looks vibrant on a white card may become difficult to distinguish on a dark surface. Secondary labels, gridlines and tooltip backgrounds also need appropriate contrast. Reserve highly saturated colours for important information and let quieter elements provide structure. Good thematic integration makes charts appear designed as part of the interface rather than inserted from an unrelated demo.
Make tooltips and legends feel native
Tooltips are small interfaces embedded within a visualisation. They should use the same type scale, spacing, border treatment and number formatting as neighbouring product components. The shadcn/ui chart helpers can simplify those choices, but developers must still decide which content belongs in the tooltip. Prefer readable metric names to raw data keys, show units and avoid repeating information that is already visible in a concise label.
Likewise, legends require an editorial decision. They are useful when several series share one plot, but may be unnecessary for a single clearly titled series. Consider how labels wrap on narrower screens and whether long names crowd the chart itself. For keyboard accessibility, important information should not exist solely in a pointer-driven overlay. A compact text description can explain the trend, while a tabular alternative can expose exact figures where those figures carry operational significance.
Prepare layouts for real dashboard constraints
Component examples often appear inside generous demonstration cards, whereas actual products involve responsive grids, sidebars and variable content. Give chart containers a predictable minimum height and test how they behave when a parent column collapses. The data graphic should not overflow a narrow card, and the chart should not disappear because an ancestor lacks dimensions. ResponsiveContainer can adapt to available space only when the surrounding layout provides space to measure.
At mobile widths, shorten axis labels, display fewer ticks and consider whether a chart truly needs multiple series at once. Sometimes a small summary with a link to a fuller analysis is more useful than a compressed plot. Check tooltip positioning, legend wrapping and the behaviour of cards with lengthy headings. These details determine whether charts support decision-making in daily use, especially for readers who consult operational dashboards on a phone.
Upgrade deliberately rather than cosmetically
When Recharts or the shadcn/ui chart components change, treat the update as an interface migration rather than a routine colour adjustment. Review the current guidance for chart tokens, tooltip APIs and container sizing, because small integration differences can affect many charts at once. Test a representative selection: a line chart, a bar chart, a tooltip with custom content and any chart with unusually complex labels. Keep the tests close to actual product usage.
Document the colour tokens and shared chart conventions so future contributors understand why they exist. Avoid copying large component examples into every page when a smaller shared pattern will suffice. Conversely, do not hide all Recharts capabilities behind a restrictive abstraction; the value of the integration is that the underlying components remain available. A disciplined design system gives developers a consistent starting point while leaving room for data-specific expression when it is genuinely necessary.
Conclusion
Recharts provides the expressive charting primitives, while shadcn/ui helps those primitives participate in a coherent interface. Define purposeful colour tokens, protect container dimensions and test interaction across themes and screen sizes. A successful integration is visually consistent without sacrificing the flexibility needed to explain different kinds of data.

