Skip to main content

Chart

Chart building blocks for Recharts with theme-aware series colors, a clip reveal, a spring tooltip and an interactive legend.

recharts
Jan-Jun·total=2287

Customize

Tooltip blur (px)3
Legend stagger (ms)32
Speed1

Installation

npx shadcn@latest add @kinetic/chart

Usage

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.

PropTypeDefaultDescription
configChartConfig-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.
animatedbooleantrueEnables WAAPI clip-path surface entrance (260ms), series highlight fading, and serves as context default for tooltip and legend.
speednumber1Shared 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.

PropTypeDefaultDescription
indicator"line" | "dot" | "dashed" | "none""dot"Color swatch geometry rendered beside each series entry, or none to hide it.
blurPxnumber3Initial blur radius in pixels cleared by a tooltip spring on reveal (clamped 0-16).
hideLabel / hideIndicatorbooleanfalse / falseToggles tooltip header label and series swatch indicators.
nameKey / labelKeystring-Custom payload keys used to resolve series labels and tooltip headers from ChartConfig.
animated / speedboolean / numbertrue / 1Optional 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.

PropTypeDefaultDescription
hideIconbooleanfalseHides series color swatches or custom icons inside the legend.
nameKeystring-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.
staggerMsnumber32Delay in milliseconds between consecutive legend items on reveal.
animated / speedboolean / numbertrue / 1Optional overrides for legend stagger, highlight indicator, and series fade speed.

Notes

Always give ChartContainer a minimum height class (such as min-h-[200px]) so ResponsiveContainer measures non-zero bounds, and pass accessibilityLayer on Recharts chart roots.