Skip to content

Search docs

Search components and documentation

New
Menu

Chart

Composable charts built on Recharts, themed through your CSS tokens.

Area Chart
Showing total visitors for the last 6 months

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 chart

Prefer 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

Bar Chart
January - June 2024

Line (multiple series)

Line Chart - Multiple
January - June 2024

Stacked area

Area Chart - Stacked
Showing total visitors for the last 6 months

Radar

Radar Chart
January - June 2024

Radial

Radial Chart
January - June 2024

Donut

Pie Chart - Donut
January - June 2024

Live playground

Edit the component props and inspect the exact JSX before copying it. The preview loads only when this section enters the viewport.

Generated JSX
<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.

View JSON

ChartConfig

Type
type ChartConfig = { [k in string]: { label?: React.ReactNode icon?: React.ComponentType } & ( | { color?: string; theme?: never } | { color?: never; theme: Record<keyof typeof THEMES, string> } ) }

ChartContainer

Component
Props: React.ComponentProps<"div"> & { config: ChartConfig children: React.ComponentProps< typeof RechartsPrimitive.ResponsiveContainer >["children"] }
PropTypeRequiredDefaultDescription
childrenReact.ComponentProps< typeof RechartsPrimitive.ResponsiveContainer >["children"]Yes——
configChartConfigYes——

ChartTooltip

Component

Direct alias of RechartsPrimitive.Tooltip.

ChartTooltipContent

Component
Props: 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" >
PropTypeRequiredDefaultDescription
indicator"line" | "dot" | "dashed"No"dot"—
hideLabelbooleanNofalse—
hideIndicatorbooleanNofalse—
nameKeystringNo——
labelKeystringNo——

ChartLegend

Component

Direct alias of RechartsPrimitive.Legend.

ChartLegendContent

Component
Props: React.ComponentProps<"div"> & { hideIcon?: boolean nameKey?: string } & RechartsPrimitive.DefaultLegendContentProps
PropTypeRequiredDefaultDescription
hideIconbooleanNofalse—
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.
nameKeystringNo——

ChartStyle

Component
Props: { id: string; config: ChartConfig }
PropTypeRequiredDefaultDescription
idstringYes——
configChartConfigYes——

Accessibility contract

Machine-readable behavior and consumer responsibilities for chart.

View JSON
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.