Charts are a thin, composable layer over Recharts. You
bring the Recharts primitives; logic2b gives you ChartContainer (theme +
responsive wrapper), a ChartConfig type that maps each data key to a label and
a color, and theme-aware ChartTooltip / ChartLegend. Colors come from the
--chart-1…5 tokens, so every chart tracks light and dark automatically.
Installation
npx logic2b@next add chartPrefer a ready-made chart? Every example on this page (and in the
charts gallery) is an installable registry item — e.g.
npx logic2b@next add chart-area-01 copies the full card-wrapped chart
into components/charts/.
Usage
import { Area, AreaChart, CartesianGrid, XAxis } from "recharts"
import {
ChartConfig,
ChartContainer,
ChartTooltip,
ChartTooltipContent,
} from "@/components/ui/chart"
const chartData = [
{ month: "January", desktop: 186 },
{ month: "February", desktop: 305 },
{ month: "March", desktop: 237 },
]
const chartConfig = {
desktop: { label: "Desktop", color: "var(--chart-1)" },
} satisfies ChartConfig
export function Example() {
return (
<ChartContainer config={chartConfig} className="h-[240px] w-full">
<AreaChart data={chartData}>
<CartesianGrid vertical={false} />
<XAxis dataKey="month" tickLine={false} axisLine={false} />
<ChartTooltip content={<ChartTooltipContent />} />
<Area dataKey="desktop" fill="var(--color-desktop)" stroke="var(--color-desktop)" />
</AreaChart>
</ChartContainer>
)
}
Every key in chartConfig becomes a --color-<key> CSS variable inside the
container, so you reference var(--color-desktop) rather than hardcoding a hue.
Examples
Bar
Line (multiple series)
Stacked area
Radar
Radial
Donut
Live playground
Edit the component props and inspect the exact JSX before copying it. The preview loads only when this section enters the viewport.
<ChartContainer
className="h-64 w-full max-w-lg"
config={{ "visitors": { "label": "Visitors", "color": "var(--chart-1)" } }}
role="img"
aria-label="Monthly visitors from January to June 2026"
>
<BarChart
accessibilityLayer
data={[{ "month": "Jan", "visitors": 186 }, { "month": "Feb", "visitors": 305 }, { "month": "Mar", "visitors": 237 }, { "month": "Apr", "visitors": 273 }, { "month": "May", "visitors": 209 }, { "month": "Jun", "visitors": 314 }]}
margin={{ "left": 8, "right": 8 }}
>
<CartesianGrid />
<XAxis
dataKey="month"
tickMargin={10}
/>
<Bar
dataKey="visitors"
fill="var(--color-visitors)"
radius={6}
/>
</BarChart>
</ChartContainer>API reference
Generated from the public TypeScript exports in src/ui/chart.tsx.
ChartConfig
Typetype ChartConfig = { [k in string]: { label?: React.ReactNode icon?: React.ComponentType } & ( | { color?: string; theme?: never } | { color?: never; theme: Record<keyof typeof THEMES, string> } ) }ChartContainer
ComponentProps: React.ComponentProps<"div"> & { config: ChartConfig children: React.ComponentProps< typeof RechartsPrimitive.ResponsiveContainer >["children"] }| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
children | React.ComponentProps< typeof RechartsPrimitive.ResponsiveContainer >["children"] | Yes | — | — |
config | ChartConfig | Yes | — | — |
ChartTooltip
ComponentDirect alias of RechartsPrimitive.Tooltip.
ChartTooltipContent
ComponentProps: React.ComponentProps<typeof RechartsPrimitive.Tooltip> & React.ComponentProps<"div"> & { hideLabel?: boolean hideIndicator?: boolean indicator?: "line" | "dot" | "dashed" nameKey?: string labelKey?: string } & Omit< RechartsPrimitive.DefaultTooltipContentProps< TooltipValueType, TooltipNameType >, "accessibilityLayer" >| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
indicator | "line" | "dot" | "dashed" | No | "dot" | — |
hideLabel | boolean | No | false | — |
hideIndicator | boolean | No | false | — |
nameKey | string | No | — | — |
labelKey | string | No | — | — |
ChartLegend
ComponentDirect alias of RechartsPrimitive.Legend.
ChartLegendContent
ComponentProps: React.ComponentProps<"div"> & { hideIcon?: boolean nameKey?: string } & RechartsPrimitive.DefaultLegendContentProps| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
hideIcon | boolean | No | false | — |
verticalAlign | "top" | "bottom" | "middle" | No | "bottom" | Vertical alignment of the whole Legend container: - `bottom`: shows the Legend below chart, and chart height reduces automatically to make space for it. - `top`: shows the Legend above chart, and chart height reduces automatically. - `middle`: shows the Legend in the middle of chart, covering other content, and chart height remains unchanged. The exact behavior changes depending on `align` prop. |
nameKey | string | No | — | — |
ChartStyle
ComponentProps: { id: string; config: ChartConfig }| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
id | string | Yes | — | — |
config | ChartConfig | Yes | — | — |
Accessibility contract
Machine-readable behavior and consumer responsibilities for chart.
- Support
- Composition contract
- Pattern
- data visualization
- Recharts
Built-in semantics
- Chart containers can expose a labelled figure while tooltip content is available to pointer and keyboard interactions supported by the composed chart.
Consumer responsibilities
- Provide a concise chart name, units and a textual or tabular equivalent for the underlying data.
Known limitations
- • Canvas/SVG marks alone are not a complete accessible data representation.