Make your AI a shadcn expert

Shadcn Chart

React chart for dashboards and analytics. Built with TypeScript and Tailwind CSS for Next.js using Base UI — themed tooltips, legends, and CSS variable colors.

A chart is Recharts with your theme on the container, tooltip, and legend. You write BarChart and Bar yourself — config only supplies labels and --color-*. Use it on dashboards, reports, and any plot that should match the rest of the app.

Scroll to load preview...

Usage

import {
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  type ChartConfig,
} from "@/components/ui/chart"
import { Bar, BarChart } from "recharts"
const chartConfig = {
  desktop: { label: "Desktop", color: "var(--chart-1)" },
} satisfies ChartConfig

<ChartContainer config={chartConfig} className="min-h-[200px] w-full">
  <BarChart accessibilityLayer data={chartData}>
    <Bar dataKey="desktop" fill="var(--color-desktop)" />
    <ChartTooltip content={<ChartTooltipContent />} />
  </BarChart>
</ChartContainer>

config keys must match each dataKey. fill="var(--color-desktop)" reads the color the container injects.

Composition

ChartTooltipContent

ChartStyle is internal. ChartTooltip and ChartLegend are the Recharts primitives.

Example

Two series, no axis. fill is var(--color-desktop) from config.

Scroll to load preview...

Tooltip

indicator is dot, line, or dashed. hideLabel and hideIndicator drop the parts you do not want.

Scroll to load preview...

Grid

Turn the cartesian grid on or off. Same data, less chrome.

Scroll to load preview...

Axis

Format ticks. Hide an axis when the tooltip already says the number.

Scroll to load preview...

Tooltip Example

A custom tooltip renderer. Keep it to the series they hovered.

Scroll to load preview...

Legend

ChartLegendContent under the plot. Click to toggle a series if the chart supports it.

Scroll to load preview...

RTL

Wrap with DirectionProvider and dir="rtl". reversed on XAxis so months read right to left.

Scroll to load preview...

API

Prop

Type

ChartConfig

Prop

Type

ChartTooltipContent

Prop

Type

ChartLegendContent

Prop

Type

Notes

Give the container a height

ResponsiveContainer measures the parent. Keep min-h-*, h-*, or aspect-* on ChartContainer or the plot is 0px tall.

Write colors as var(--chart-1), not hsl(var(--chart-1)).

With other components

Questions

Was this page helpful?

Sign in to leave feedback.