Ballmac UI home

Chart

Theme-aware chart wrapper for Recharts with token colors, a styled tooltip and legend, a named figure with a screen-reader summary, and keyboard navigation.

Revenue

April to September

Revenue grew from $18,200 in April to $34,600 in September. Refunds stayed between $900 and $2,100.

Installation

$ pnpm dlx shadcn@latest add @ballmac/chart

Usage

import { ChartContainer, ChartTooltip, ChartTooltipContent, ChartLegend, ChartLegendContent, ChartStyle, useChart } from "@/components/ballmac/chart"

The full example is in the Code tab above.

Examples

Grouped bars

Web sessions peak on Tuesday at 305. Mobile peaks the same day at 200.

Donut

Search brings the most visitors (4,210), followed by direct (2,890), social (1,630) and email (980).

API reference

<ChartContext>

PropTypeDefault
config*ChartConfig—

<ChartContainer>

PropTypeDefault
config*

Series definitions keyed by the chart's `dataKey`. Each becomes a `--color-<key>` CSS variable.

ChartConfig—
children*

One Recharts chart (AreaChart, BarChart, LineChart, PieChart, RadarChart…).

React.ComponentProps<typeof RechartsPrimitive.ResponsiveContainer>["children"]—
label*

Accessible name of the figure.

string—
summary

Plain-language summary of what the chart shows, read by screen readers.

string—
initialDimension

Size used before the container is measured, so the server render has a stable box.

{ width: number; height: number }{ width: 480, height: 270 }
width*number—
height*number—

<ChartTooltipContent>

PropTypeDefault
activeboolean—
payloadPayloadItem[]—
labelReact.ReactNode—
classNamestring—
indicator

Marker style before each value.

"dot" | "line" | "dashed""dot"
hideLabelbooleanfalse
hideIndicatorbooleanfalse
labelKey

Key in the data point whose value is used as the tooltip title.

string—
nameKey

Key used to look up the series name and color in `config`.

string—
labelFormatter(label: React.ReactNode, payload: PayloadItem[]) => React.ReactNode—
formatter(value: number | string, name: string, item: PayloadItem, index: number) => React.ReactNode—
labelClassNamestring—
colorstring—

<ChartLegendContent>

PropTypeDefault
payloadArray<{ value?: string | number; dataKey?: string | number; color?: string; type?: string }>—
verticalAlign"top" | "middle" | "bottom""bottom"
hideIconbooleanfalse
nameKey

Key used to look up the series in `config`.

string—
valuestring | number—
dataKeystring | number—
colorstring—
typestring—

Also accepts the standard attributes of its root element.

Accessibility

KeyAction
Arrow keysMove between data points (accessibilityLayer)
Screen readersRead the figure name and summary

Use with AI

Wrap any Recharts chart in ChartContainer with a config of label and color per series. Use ChartTooltipContent and ChartLegendContent. Always pass label and summary. With the shadcn MCP server set up (guide), ask your agent:

Add the Ballmac UI Chart (@ballmac/chart) to this project with the shadcn MCP, then use it where it fits.

Use it for

  • Dashboards and reports
  • Trends, comparisons and proportions

Not for

  • A tiny inline trend; use sparkline
  • A single ring value; use progress-ring

Registry JSON: https://ui.ballmac.com/r/chart.json

Credits

Based on shadcn/ui Chart, adapted by Ballmac. Free to use in personal and commercial projects.

Registry
shadcn/utils