Chart

shadcn/ui's Recharts charts, restyled after Swift Charts: secondary axis labels, hairline grids, round markers and a glass tooltip.

@cupertinoui/chartRegistry JSON

Installation

pnpm dlx shadcn@latest add @cupertinoui/chart

The first install also adds the macOS theme. See Installation to set up the registry.

Usage

import { Bar, BarChart, XAxis } from "recharts"

import {
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  type ChartConfig,
} from "@/components/ui/chart"

const config = {
  hours: { label: "Hours", color: "var(--chart-1)" },
} satisfies ChartConfig

<ChartContainer config={config} className="h-48 w-full">
  <BarChart data={data}>
    <XAxis dataKey="day" tickLine={false} axisLine={false} />
    <ChartTooltip content={<ChartTooltipContent />} />
    <Bar dataKey="hours" fill="var(--color-hours)" radius={3} />
  </BarChart>
</ChartContainer>
The same component as shadcn/ui's Chart, for Recharts 3: compose any Recharts chart inside ChartContainer, and the config names each series, with its label and color. Code written for the shadcn chart works unchanged.
Restyled after Swift Charts on macOS: 11pt secondary axis labels with tabular figures, hairline grid lines in the separator color (pass strokeDasharray for the dashed look), round markers in the legend and tooltip, and a tooltip on the popover's glass material.
Each config key becomes a CSS variable, --color-<key>, to use as fill or stroke. --chart-1 to --chart-5 are the macOS system colors (blue, green, orange, purple and pink), and any var(--mac-…) color works too. theme gives a series separate light and dark colors.

Examples

Area

Areas with a gradient fill and a line tooltip that follows the pointer, like Activity Monitor's network graph.

Line

Lines with a legend; theme gives a series its own color in light and dark.

Battery Level

Hourly bars as in System Settings, brighter while charging, with a custom tooltip row.

CPU Load

Stacked areas as in Activity Monitor, with a line tooltip and a legend.

API Reference

Every part forwards the props of the underlying element. The props below are the ones CupertinoUI adds or changes.

ChartContainer

Wraps a Recharts chart, makes it responsive and applies the styles.

PropTypeDescription
configChartConfigThe series by data key: { label, color } or { label, theme: { light, dark } }, and an optional icon for the legend and tooltip.
initialDimension{ width: number; height: number }
Default: { width: 320, height: 200 }
The size used before the container is measured, e.g. when rendering on the server.
classNamestringExtra classes, merged with the component's own.

ChartTooltipContent

The content for ChartTooltip.

PropTypeDescription
indicator"dot" | "line" | "dashed"
Default: "dot"
The marker before each series.
hideLabel / hideIndicatorboolean
Default: false
Hide the label at the top, or the markers.
labelKey / nameKeystringConfig keys for the label and the series names, when they aren't the data keys.
labelFormatter / formatterfunctionFormat the label, or render a series row yourself.
classNamestringExtra classes, merged with the component's own.

ChartLegendContent

The content for ChartLegend.

PropTypeDescription
hideIconboolean
Default: false
Show round markers even when the config has icons.
nameKeystringThe config key for the series names.
classNamestringExtra classes, merged with the component's own.