Skip to content

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

Free

A simple pie chart for Ark UI

One slice per browser, sized by visitors and colored from the chart config. The tooltip names the browser and its count.

One slice per browser, sized by visitors and colored from the chart config. The tooltip names the browser and its count. There is no legend and no label on the slices.

Use a pie for a handful of parts of a whole. Past that, bars or a Table are easier to compare. In React, Ark UI maps each slice color to a variable. The counts are 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]"
    config={chartConfig}
  >
    <PieChart>
      <ChartTooltip content={renderTooltipContent} cursor={false} />
      <Pie data={chartData} dataKey="visitors" nameKey="browser" />
    </PieChart>
  </ChartContainer>
</div>

FAQ

How is each slice built?

Pie sets data={chartData}, dataKey="visitors", and nameKey="browser". visitors is the slice size, from Chrome at 275 to Other at 90. nameKey is the field the tooltip uses as the slice name.

Where does a slice's color come from?

Each row sets fill to var(--color-chrome) or the matching browser key. config maps those keys to var(--chart-1) through var(--chart-5) and to the labels Chrome, Safari, Firefox, Edge, and Other. ChartContainer writes the --color- variables.

Why does the tooltip say Chrome and not visitors?

Pie sets nameKey="browser", so the hovered slice is named chrome (and the other keys). ChartTooltipContent looks that key up in config and shows the label. hideLabel hides the title. cursor={false} turns the hover cursor off.

How do I add a slice?

Add a row to chartData with browser, visitors, and fill, and add the same key to config with a label and a color. Pie reads the whole array. This file doesn't set innerRadius, so the slices meet in the middle.

What sets the order of the slices?

The order of chartData. This demo lists chrome, safari, firefox, edge, then other. There is no ChartLegend and no LabelList, so the names show up in the tooltip.

How do I keep the pie square?

ChartContainer sets mx-auto aspect-square max-h-[250px] inside a w-full max-w-xl frame. That overrides the container's default 16:9 box.

API Reference

Chart

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