Skip to content

shadcn.io is an independent project built on shadcn/ui

Free

A pie chart with a label for Ark UI

Each browser slice has its visitor count outside the pie, joined to the slice by a short line. The tooltip still names the browser.

The visitor count sits outside each browser slice, tied to it by a short line. Hover still names the browser and shows the same count.

Use outside labels when the values must be readable without a hover. Names inside the slices, or a Table, work better when the numbers collide. In React, Ark UI does not put the counts outside the pie. The label reads the rows you pass.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.
Use email insteadNo credit card

Anatomy

Chart anatomy: container, grid, axis, bar, tooltip, legend

Usage

<div className="w-full max-w-xl rounded-md border bg-background p-4">
  <ChartContainer
    className="mx-auto aspect-square max-h-[250px] pb-0 [&_.recharts-pie-label-text]:fill-foreground"
    config={chartConfig}
  >
    <PieChart>
      <ChartTooltip content={renderTooltipContent} />
      <Pie data={chartData} dataKey="visitors" label nameKey="browser" />
    </PieChart>
  </ChartContainer>
</div>

FAQ

How do the numbers get outside the slices?

Pie sets label and dataKey to visitors, so each slice prints its visitor count outside the pie. nameKey is browser. This file leaves labelLine unset, so the connector from the slice to that number stays on.

How is the outside text colored?

ChartContainer adds [&_.recharts-pie-label-text]:fill-foreground to mx-auto aspect-square max-h-[250px], plus pb-0. That selector paints the label text with the foreground color.

Which numbers are printed?

Chrome is 275, Safari 200, Firefox 187, Edge 173, and Other 90. The text beside the slice is that visitors value. The browser name is the slice's nameKey.

How are the slices colored?

Each row sets fill to var(--color-chrome) or the matching browser variable. config maps chrome through other to --chart-1 through --chart-5 and to labels Chrome, Safari, Firefox, Edge, and Other.

What does the tooltip show?

ChartTooltipContent sets hideLabel. The row name comes from nameKey browser, looked up in config, and the value is the visitor count.

Why is the pie square?

ChartContainer uses aspect-square and max-h-[250px], centered with mx-auto. The frame around it is w-full max-w-xl with a border and padding.

API Reference

Chart

Sets config={chartConfig} and content={renderTooltipContent}. The rest is on the Chart page.