shadcn.io is not affiliated with official shadcn/ui
About
Use it when two parts add up to one total and the total is the headline: desktop and mobile visitors, paid and free plans. The half ring reads as a gauge and leaves room for the number. With more than three parts, or when the parts matter more than the sum, a donut or a stacked bar is clearer.
Mobile runs from three o'clock, desktop picks up where it ends and carries on over the top to nine o'clock. The ends are rounded and a thin gap separates the two. The total sits in the middle, Visitors under it.
Installation
Usage
import { ChartRadialStacked } from "@/components/charts/chart-radial-stacked";<ChartRadialStacked />Customize
- Two
<RadialBar>s withstackId="a"stack mobile and desktop along the arc; their order in JSX is the stack order. endAngle={180}withinnerRadius={80}andouterRadius={110}on<RadialBarChart>makes the half ring.cornerRadius={5}rounds the segments, which opens the notch between them;className="stroke-2 stroke-transparent"keeps their outline invisible.totalVisitorsadds the two keys; a<Label>inside<PolarRadiusAxis axisLine={false} tick={false} tickLine={false}>prints it atviewBox.cy - 16.<ChartTooltipContent hideLabel />lists both series fromchartConfig.
FAQ
How are the two series stacked?
Two <RadialBar>s share stackId="a", dataKey="mobile" first and dataKey="desktop" second. Recharts lays the second after the first; the JSX order is the stack order.
How do I make it a full or three-quarter ring?
endAngle={180} on <RadialBarChart>, with the default startAngle={0}: degrees from three o'clock, counterclockwise. Set endAngle={270} for three quarters or 360 for a full ring.
Where does the gap between the segments come from?
cornerRadius={5} rounds both ends of each <RadialBar>, which opens the notch where they meet; className="stroke-2 stroke-transparent" keeps the sectors' outline invisible. Use stroke-background for a visible seam.
How do I add a third series?
Add the key to the row and to chartConfig, then a third <RadialBar dataKey="tablet" stackId="a" fill="var(--color-tablet)" />. totalVisitors sums the keys for the center, so add it there too.
API Reference
ChartContainer
configChartConfig
Each series by its data key: its label, an icon, and a color (or a * theme color per light and dark), read by the tooltip and legend and set * as --color-<key>.
initialDimension?{ height: number; width: number; }
The size it renders at before it's measured, so the first paint isn't * empty.
- Type
{ height: number; width: number; }- Default
INITIAL_DIMENSION
className?string
Merged with the part's classes.
ChartLegend
ChartLegendContent
<div>
hideIcon?boolean
Hides each series' icon (from config), leaving its color swatch.
- Default
false
nameKey?string
The key in each legend item's data to look its label up by in config. * Defaults to the item's dataKey.
className?string
Merged with the part's classes.
ChartStyle
<style>
configChartConfig
The chart config whose colors it writes as --color-<key> variables.
idstring
The element's id.
ChartTooltip
ChartTooltipContent
<div>
hideIndicator?boolean
Hides each item's color indicator.
- Default
false
hideLabel?boolean
Hides the tooltip's label, the hovered point's.
- Default
false
indicator?"dashed" | "dot" | "line"
The color indicator's shape: a dot, a line or dashed.
- Type
"dashed" | "dot" | "line"- Default
"dot"
labelFormatter?(label: any, payload: TooltipPayload) → React.ReactNode
Formats the tooltip's label; its value is untyped, as in recharts 3.8.
- Type
(label: any, payload: TooltipPayload) → React.ReactNode- Parameters
label– anypayload– TooltipPayload- Returns
React.ReactNode
labelKey?string
The key in the data to read the label from, looked up in config.
nameKey?string
The key in each item's data to look its name up by in config.
className?string
Merged with the part's classes.
Related
Radial Chart with Text
Radial chartsOne ring of progress with the total in its center.
Radial Chart with Custom Shape
Radial chartsA thick ring with a custom end angle and the total inside.
Stacked Pie Chart
Pie chartsTwo rings of slices, one series inside the other.
Donut Chart with Text
Pie chartsA donut with the total written in its center.
Stacked Bar Chart with Legend
Bar chartsTwo series stacked in each bar, with a legend.
Radial Chart
Radial chartsOne ring per browser, each as long as its share.