Skip to content
Logic2BUI

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@latest 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@latest 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

API

Export Description
ChartContainer Responsive wrapper. Props: config: ChartConfig, children. Emits the --color-* variables.
ChartConfig Record<string, { label?: ReactNode; icon?: Component; color?: string; theme?: { light: string; dark: string } }>.
ChartTooltip Recharts Tooltip wired to the theme. Use with content={<ChartTooltipContent />}.
ChartTooltipContent Themed tooltip body. Props: hideLabel, hideIndicator, indicator (dot | line | dashed), nameKey, labelKey.
ChartLegend Recharts Legend wrapper. Use with content={<ChartLegendContent />}.
ChartLegendContent Themed legend. Props: hideIcon, nameKey.