Chart
Beautiful charts. Built using Solid Recharts. Copy and paste into your apps.
The Chart component is built with Solid Recharts, a SolidJS port of Recharts. It provides configuration-aware colors, tooltips, and legends while leaving chart composition in your hands.
Charts work with the rest of the component library and are fully customizable. Browse the complete collection on the Charts page.
Component
Use Solid Recharts primitives to build a chart, then add Zaidan's ChartTooltip and ChartLegend only where they are useful. The wrapper does not hide the underlying chart library, so upgrades and custom composition remain straightforward.
import { Bar, BarChart } from "solid-recharts";import { ChartContainer, ChartTooltip, ChartTooltipContent,} from "~/components/ui/chart";
export function MyChart() { return ( <ChartContainer config={chartConfig} class="min-h-50"> <BarChart data={data} accessibilityLayer> <Bar dataKey="value" /> <ChartTooltip content={(props) => <ChartTooltipContent {...props} />} /> </BarChart> </ChartContainer> );}Updating to Solid Recharts
Use var(--chart-1) rather than hsl(var(--chart-1)) when referencing chart tokens. Keep a height, min-h-*, or aspect-* class on ChartContainer so ResponsiveContainer can measure on first render. The Solid port uses class and native Solid event handlers in place of React-only props and synthetic events.
Installation
Your First Chart
Build a bar chart with a grid, axis, tooltip, and legend.
Define the data
The following data represents the number of desktop and mobile users for each month. Your data can use any shape; map each field with dataKey.
const chartData = [ { month: "January", desktop: 186, mobile: 80 }, { month: "February", desktop: 305, mobile: 200 }, { month: "March", desktop: 237, mobile: 120 }, { month: "April", desktop: 73, mobile: 190 }, { month: "May", desktop: 209, mobile: 130 }, { month: "June", desktop: 214, mobile: 140 },];Define the chart config
The chart config holds human-readable labels, icons, and color tokens.
import type { ChartConfig } from "~/components/ui/chart";
const chartConfig = { desktop: { label: "Desktop", color: "#2563eb" }, mobile: { label: "Mobile", color: "#60a5fa" },} satisfies ChartConfig;Build the chart
Give ChartContainer a height, minimum height, or aspect ratio so its responsive container can measure on first render.
Add a Grid
Add CartesianGrid to show horizontal guides.
import { Bar, BarChart, CartesianGrid } from "solid-recharts";
<ChartContainer config={chartConfig} class="min-h-[200px] w-full"> <BarChart accessibilityLayer data={chartData}> <CartesianGrid vertical={false} /> <Bar dataKey="desktop" fill="var(--color-desktop)" radius={4} /> <Bar dataKey="mobile" fill="var(--color-mobile)" radius={4} /> </BarChart></ChartContainer>;Add an Axis
Use XAxis to label the data points.
import { Bar, BarChart, CartesianGrid, XAxis } from "solid-recharts";
<ChartContainer config={chartConfig} class="min-h-[200px] w-full"> <BarChart accessibilityLayer data={chartData}> <CartesianGrid vertical={false} /> <XAxis dataKey="month" tickLine={false} tickMargin={10} axisLine={false} tickFormatter={(value) => String(value).slice(0, 3)} /> <Bar dataKey="desktop" fill="var(--color-desktop)" radius={4} /> <Bar dataKey="mobile" fill="var(--color-mobile)" radius={4} /> </BarChart></ChartContainer>;Add Tooltip
ChartTooltip accepts a function so Solid Recharts can inject its active payload into ChartTooltipContent.
import { ChartTooltip, ChartTooltipContent } from "~/components/ui/chart";
<ChartTooltip content={(props) => <ChartTooltipContent {...props} />} />;Hover a bar to see the tooltip.
Add Legend
Use the same function-form composition to add a legend.
import { ChartLegend, ChartLegendContent } from "~/components/ui/chart";
<ChartLegend content={(props) => <ChartLegendContent {...props} />} />;Chart Config
Chart config is intentionally decoupled from chart data. This lets labels, icons, colors, and remote data evolve independently.
import Monitor from "lucide-solid/icons/monitor";import type { ChartConfig } from "~/components/ui/chart";
const chartConfig = { desktop: { label: "Desktop", icon: Monitor, color: "#2563eb", }, mobile: { label: "Mobile", theme: { light: "#60a5fa", dark: "#2563eb", }, },} satisfies ChartConfig;Theming
Use CSS variables (recommended) or direct hex, hsl, or oklch colors. Reference configured colors in chart primitives as var(--color-KEY).
CSS Variables
Define chart tokens in your CSS, then reference them from the config.
:root { --chart-1: oklch(0.646 0.222 41.116); --chart-2: oklch(0.6 0.118 184.704);}
.dark { --chart-1: oklch(0.488 0.243 264.376); --chart-2: oklch(0.696 0.17 162.48);}const chartConfig = { desktop: { label: "Desktop", color: "var(--chart-1)" }, mobile: { label: "Mobile", color: "var(--chart-2)" },} satisfies ChartConfig;Direct colors
Use the color format that fits your application when CSS tokens are not appropriate.
const chartConfig = { desktop: { label: "Desktop", color: "#2563eb" }, mobile: { label: "Mobile", color: "hsl(220 98% 61%)" }, tablet: { label: "Tablet", color: "oklch(0.5 0.2 240)" }, laptop: { label: "Laptop", color: "var(--chart-2)" },} satisfies ChartConfig;Using colors
Use var(--color-KEY) in chart components, data, and Tailwind classes.
<Bar dataKey="desktop" fill="var(--color-desktop)" />const chartData = [ { browser: "chrome", visitors: 275, fill: "var(--color-chrome)" }, { browser: "safari", visitors: 200, fill: "var(--color-safari)" },];<LabelList class="fill-(--color-desktop)" />Tooltip
Use hideLabel, hideIndicator, and indicator to customize tooltip content. Use labelKey and nameKey when the chart data uses different field names.
<ChartTooltip content={(props) => ( <ChartTooltipContent {...props} labelKey="visitors" nameKey="browser" /> )}/>Colors
Tooltip colors are resolved automatically from chartConfig.
Custom keys
Pass labelKey and nameKey when data uses a different key for the tooltip label or series name.
const chartData = [ { browser: "chrome", visitors: 187, fill: "var(--color-chrome)" }, { browser: "safari", visitors: 200, fill: "var(--color-safari)" },];
const chartConfig = { visitors: { label: "Total Visitors" }, chrome: { label: "Chrome", color: "var(--chart-1)" }, safari: { label: "Safari", color: "var(--chart-2)" },} satisfies ChartConfig;Legend
import { ChartLegend, ChartLegendContent } from "~/components/ui/chart";
<ChartLegend content={(props) => <ChartLegendContent {...props} nameKey="browser" />}/>;nameKey maps a legend item to a different config key.
Colors
Colors are automatically referenced from the chart config.
Custom keys
const chartData = [ { browser: "chrome", visitors: 187, fill: "var(--color-chrome)" }, { browser: "safari", visitors: 200, fill: "var(--color-safari)" },];
const chartConfig = { chrome: { label: "Chrome", color: "var(--chart-1)" }, safari: { label: "Safari", color: "var(--chart-2)" },} satisfies ChartConfig;
<ChartLegend content={(props) => <ChartLegendContent {...props} nameKey="browser" />}/>;Accessibility
Set accessibilityLayer on the Solid Recharts chart component to enable its keyboard navigation and screen-reader descriptions.
<BarChart accessibilityLayer data={chartData}> {/* ... */}</BarChart>API Reference
Chart composes Solid Recharts, whose chart primitives preserve the Recharts API. Refer to that API and the exported Zaidan ChartContainer, ChartTooltip, ChartTooltipContent, ChartLegend, and ChartLegendContent types for composition details.