shadcn.io is not affiliated with official shadcn/ui
Chart examples · Pie
A pie chart with stacked sections for React
Two nested pie rings comparing desktop and mobile visitors by month.
Use two rings to compare two series over the same categories. Desktop is the inner pie and mobile the ring around it, both by month and in the same colors, so January sits in the same color in both.
Preview
Installation
FAQ
How are the two rings sized?
The inner Pie uses desktopData, dataKey desktop, and outerRadius 60. The outer Pie uses mobileData, dataKey mobile, innerRadius 70, and outerRadius 90. The outer ring starts 10px past the inner ring.
How do the rings share colors?
Both arrays set fill to var(--color-january) and the same pattern for February through May. config gives each month a color from --chart-1 through --chart-5 and a label such as January. A month uses that color on both rings.
How does the tooltip name the ring?
ChartTooltipContent sets indicator to line, labelKey to visitors, and nameKey to month. labelFormatter is formatRingLabel, which reads the hovered dataKey and returns the Desktop or Mobile label from config.
What does nameKey month put on the row?
nameKey is month, and each row's month is a key such as january. config labels that key January. The title from formatRingLabel says which ring you are on, Desktop or Mobile.
Related
- A donut chartA donut chart of visitors by browser, a
- A simple pie chartA pie chart of visitors by browser, each
- A stacked area chartAn area chart stacking desktop and mobile
- A stacked bar chart with a legendA bar chart stacking desktop and mobile
- A multiple line chartA line chart comparing desktop and mobile
- A radial chart with stacked sectionsA half-circle radial chart stacking