About
A composable chart container that wraps Recharts with theme-aware colors, an accessible tooltip, and a legend for building line, bar, area, donut, and sparkline charts.
Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Chart to your project and fits it to your theme.
Code
How Chart is used: the demo's code. The component's own source comes with a free account.
Usage.tsx
"use client";
import {
ChartContainer,
ChartTooltip,
ChartTooltipContent,
ChartLegend,
ChartLegendContent,
type ChartConfig,
} from "@/components/ui/chart";
import { Bar, BarChart, CartesianGrid, XAxis, YAxis } from "recharts";
const channelMix = [
{ channel: "Email", new: 720, returning: 520 },
{ channel: "Search", new: 580, returning: 400 },
{ channel: "Social", new: 460, returning: 300 },
{ channel: "Direct", new: 320, returning: 220 },
{ channel: "Referral", new: 200, returning: 120 },
];
const stackedBarConfig = {
new: {
label: "New",
theme: { light: "var(--color-chart-1)", dark: "var(--color-chart-1)" },
},
returning: {
label: "Returning",
theme: { light: "var(--color-chart-2)", dark: "var(--color-chart-2)" },
},
} satisfies ChartConfig;
export default function Demo() {
return (
<ChartContainer
config={stackedBarConfig}
ariaLabel="New vs returning signups by channel"
className="aspect-[16/9] max-h-[300px] w-full"
>
<BarChart
data={channelMix}
margin={{ top: 8, right: 16, bottom: 0, left: 0 }}
>
<CartesianGrid vertical={false} strokeDasharray="3 3" />
<XAxis dataKey="channel" tickLine={false} axisLine={false} />
<YAxis tickLine={false} axisLine={false} />
<ChartTooltip
cursor={{ fill: "var(--color-bg)" }}
content={<ChartTooltipContent />}
/>
<ChartLegend content={<ChartLegendContent />} />
<Bar
dataKey="new"
stackId="a"
fill="var(--color-new)"
radius={[0, 0, 0, 0]}
/>
<Bar
dataKey="returning"
stackId="a"
fill="var(--color-returning)"
radius={[4, 4, 0, 0]}
/>
</BarChart>
</ChartContainer>
);
}








