Chart
Chart building blocks for Recharts with theme-aware series colors, a clip reveal, a spring tooltip and an interactive legend.
Customize
Installation
npx shadcn@latest add @kinetic/chartUsage
Describe your series in a ChartConfig, then use Recharts inside ChartContainer. Colors are exposed as --color-<key>.
import { Bar, BarChart, XAxis } from "recharts";
import {
type ChartConfig,
ChartContainer,
ChartTooltip,
ChartTooltipContent,
} from "@/components/kinetic/ui/chart";
const data = [
{ month: "Jan", desktop: 186 },
{ month: "Feb", desktop: 305 },
];
const config = {
desktop: { label: "Desktop", color: "var(--chart-1)" },
} satisfies ChartConfig;
export function Visitors() {
return (
<ChartContainer config={config} className="min-h-[200px] w-full">
<BarChart accessibilityLayer data={data}>
<XAxis dataKey="month" tickLine={false} axisLine={false} />
<ChartTooltip content={<ChartTooltipContent />} />
<Bar dataKey="desktop" fill="var(--color-desktop)" radius={4} />
</BarChart>
</ChartContainer>
);
}Theme colors
Give a series theme: { light, dark } instead of color to switch colors with the theme.
const config = {
mobile: { label: "Mobile", theme: { light: "#2563eb", dark: "#60a5fa" } },
} satisfies ChartConfig;Tooltip
ChartTooltipContent takes indicator (dot, line, dashed or none), hideLabel, hideIndicator, and nameKey / labelKey to read labels from other payload fields.
<ChartTooltip content={<ChartTooltipContent indicator="line" hideLabel />} />Legend
Add ChartLegend with ChartLegendContent. Hovering a legend item highlights its series. Use hideIcon and verticalAlign to adjust it.
<ChartLegend content={<ChartLegendContent />} verticalAlign="top" />Motion preferences
Set animated={false} on ChartContainer to turn off the reveal, tooltip and legend animations. speed, blurPx and staggerMs tune them. Reduced motion shows the chart without animation.
API Reference
ChartContainer / ChartConfig
Responsive Recharts host applying scoped --color-<key> inline CSS variables per theme with WAAPI clip-path mount reveal and legend-to-series cross-highlighting.
| Prop | Type | Default | Description |
|---|---|---|---|
config | ChartConfig | - | Map of series keys to labels, optional icons, and static or light/dark theme colors. |
initialDimension | { width: number; height: number } | { width: 320, height: 200 } | Initial SSR/hydration dimensions passed to Recharts ResponsiveContainer. |
animated | boolean | true | Enables WAAPI clip-path surface entrance (260ms), series highlight fading, and serves as context default for tooltip and legend. |
speed | number | 1 | Shared speed multiplier across container reveal, tooltip, and legend animations (clamped 0.25-4). |
ChartTooltipContent
Tabular-numeral tooltip card with WAAPI pop-in (180ms) and spring blur settle reading labels and colors from ChartConfig.
| Prop | Type | Default | Description |
|---|---|---|---|
indicator | "line" | "dot" | "dashed" | "none" | "dot" | Color swatch geometry rendered beside each series entry, or none to hide it. |
blurPx | number | 3 | Initial blur radius in pixels cleared by a tooltip spring on reveal (clamped 0-16). |
hideLabel / hideIndicator | boolean | false / false | Toggles tooltip header label and series swatch indicators. |
nameKey / labelKey | string | - | Custom payload keys used to resolve series labels and tooltip headers from ChartConfig. |
animated / speed | boolean / number | true / 1 | Optional overrides for ChartContainer animation toggle and speed. |
ChartLegendContent / ChartTooltip / ChartLegend / ChartStyle
Staggered interactive legend buttons (220ms, 32ms stagger) with sliding hover/focus highlight pill and series cross-highlighting, Recharts Tooltip/Legend exports, and compatibility ChartStyle no-op.
| Prop | Type | Default | Description |
|---|---|---|---|
hideIcon | boolean | false | Hides series color swatches or custom icons inside the legend. |
nameKey | string | - | Custom payload property used to match each legend entry against ChartConfig. |
verticalAlign | "top" | "bottom" | "middle" | "bottom" | Controls top or bottom legend spacing relative to the plot area. |
staggerMs | number | 32 | Delay in milliseconds between consecutive legend items on reveal. |
animated / speed | boolean / number | true / 1 | Optional overrides for legend stagger, highlight indicator, and series fade speed. |