shadcn.io is not affiliated with official shadcn/ui
Chart examples · Pie
A pie chart with a label list for React
A pie chart with each browser's name printed inside its slice.
Use it when the names matter more than the numbers. A LabelList inside the Pie prints each browser's name from the chart config inside its slice, in the background color so it reads on every slice.
Preview
Installation
FAQ
How do the slices show Chrome inside them?
Pie nests a LabelList with dataKey browser and formatter set to formatBrowser. That function returns chartConfig[value].label, so chrome prints as Chrome. fontSize is 12 and stroke is none.
How does the text stay readable on the slices?
LabelList sets className to fill-background. ChartContainer also sets [&_.recharts-text]:fill-background on mx-auto aspect-square max-h-[250px], so the SVG text uses the background color.
What sets the size of each slice?
Pie uses dataKey visitors. The counts are Chrome 275, Safari 200, Firefox 187, Edge 173, and Other 90. The text inside the slice is the browser name from formatBrowser.
How are the slices colored?
Each row sets fill to var(--color-chrome) or the matching browser variable. config maps those keys to --chart-1 through --chart-5 and to the labels the formatter prints.
Related
- A pie chart with a labelA pie chart with each slice's value
- A pie chart with a custom labelA pie chart printing each slice's value
- A pie chart with a legendA pie chart with a wrapping legend of
- A line chart with a custom labelA line chart labeling each point with its
- A simple pie chartA pie chart of visitors by browser, each
- A bar chart with a labelA bar chart with each bar's value printed