A polar chart for visualizing categorical proportions with pie, donut, and segmented donut layouts.
PieChartruns on the UI thread. React renders the parts once; data changes, the sweep-in, the press highlight and the tooltip all update through Reanimated shared values without re-rendering. Rendering a chart requires the optionalreact-native-skiapeer (>=3.0.0).
import { PieChart } from 'heroui-native-pro';<PieChart data={...} labelKey="..." valueKey="...">
<PieChart.Slice />
<PieChart.SliceAngularInset />
<PieChart.Label />
<PieChart.Tooltip />
</PieChart>data), the fields holding each slice's label, value and optional color, and the pie layout (innerRadius, startAngle, circleSweepDegrees). Owns the canvas, the press gesture and the animation settings for every part. Set its size with className.Every part is optional. A chart with only PieChart.Slice is a plain pie.
<PieChart data={DATA} labelKey="name" valueKey="value" className="h-[220px]">
<PieChart.Slice />
</PieChart>colorKey names the field holding each slice's color. It is optional: rows without a color take the theme chart colors chart-1 … chart-5 in turn.
const DATA = [
{ name: 'Chrome', value: 62, color: '#6366f1' },
{ name: 'Safari', value: 19, color: '#7c3aed' },
{ name: 'Firefox', value: 10 }, // theme chart color
];
<PieChart
data={DATA}
labelKey="name"
valueKey="value"
colorKey="color"
className="h-[220px]"
>
<PieChart.Slice />
</PieChart>;Set innerRadius on the root, in pixels or as a percentage of the radius.
<PieChart
data={DATA}
labelKey="name"
valueKey="value"
innerRadius="68%"
className="h-[220px]"
>
<PieChart.Slice />
</PieChart>Add PieChart.SliceAngularInset to cut gaps between the slices. The gaps use the theme background color; pass color to match a different surface behind the chart.
<PieChart
data={DATA}
labelKey="name"
valueKey="value"
innerRadius="68%"
className="h-[220px]"
>
<PieChart.Slice />
<PieChart.SliceAngularInset strokeWidth={4} />
</PieChart>startAngle is in degrees clockwise from 3 o'clock, so -90 starts the first slice at 12 o'clock. circleSweepDegrees sets how much of the circle the slices share: 180 draws a half donut; negative values run counter-clockwise.
<PieChart
data={DATA}
labelKey="name"
valueKey="value"
innerRadius="55%"
startAngle={180}
circleSweepDegrees={180}
className="h-[220px]"
>
<PieChart.Slice />
</PieChart>PieChart.Label draws the slice label in the theme accent-foreground color with the chart axis font. format receives { index, label, value, percent } (percent is 0…1) and runs on the JS thread when the data changes.
import { PieChart, type PieChartLabelSlice } from 'heroui-native-pro';
const formatPercent = ({ percent }: PieChartLabelSlice) =>
`${Math.round(percent * 100)}%`;
<PieChart data={DATA} labelKey="name" valueKey="value" className="h-[220px]">
<PieChart.Slice />
<PieChart.Label format={formatPercent} />
</PieChart>;Labels sit halfway across the ring of a donut, or halfway to the edge of a pie. radiusOffset moves them, as a share of the radius. Pass a Skia font from useFont to change the typeface.
Pass a new data array and the slices glide to their new angles. Slice counts may differ between arrays. Always pass a new array: changes made to the same array in place are not detected.
<PieChart
data={series[range]}
labelKey="name"
valueKey="value"
animate={{ type: 'spring' }}
className="h-[220px]"
>
<PieChart.Slice />
</PieChart>animate is true by default (300 ms timing). Pass a timing ({ type: 'timing', duration: 500 }) or spring config, or false. animation="disable-all" turns off every animation in the chart: the data-change transition, the sweep-in and the press highlight.
animateIn sweeps the slices in from startAngle on mount (true is 700 ms; a number sets the duration). Change resetKey to replay it.
const [replay, setReplay] = useState(0);
<PieChart
data={DATA}
labelKey="name"
valueKey="value"
animateIn={1000}
resetKey={replay}
className="h-[220px]"
>
<PieChart.Slice />
</PieChart>;Long-press a slice (100 ms by default) to select it. The other slices dim to dimOpacity (default 0.4), and PieChart.Tooltip shows the slice's label and value. Dragging moves the selection between slices.
const formatShare = (value: number) => `${value}%`;
<PieChart data={DATA} labelKey="name" valueKey="value" className="h-[220px]">
<PieChart.Slice dimOpacity={0.3} />
<PieChart.Tooltip format={formatShare} />
</PieChart>;To react on the JS thread, use onSelect. It fires when the pressed slice changes, and with null when the press ends.
<PieChart
data={DATA}
labelKey="name"
valueKey="value"
onSelect={(event) => setActive(event?.row ?? null)}
>selection={{ activateAfter: 200 }} changes the press delay; selection={false} turns inspection off.
Build the content from ChartTooltipLabel and ChartTooltipValue. They show the pressed row's fields and re-render only when the selection moves to another slice. Pass the root's labelKey field as xKey. With a worklet format (or none), their text is written from the UI thread instead; see Tooltip text on the UI thread.
import { ChartTooltipLabel, ChartTooltipValue } from 'heroui-native-pro';
<PieChart.Tooltip className="rounded-xl bg-surface p-2">
<ChartTooltipLabel xKey="name" className="text-xs text-muted" />
<ChartTooltipValue dataKey="value" className="text-sm text-foreground" />
</PieChart.Tooltip>;Overlay a view on a donut for a headline number. Mark it pointerEvents="none" so it does not block the press gesture.
<View className="size-[240px]">
<PieChart
data={DATA}
labelKey="name"
valueKey="value"
innerRadius="68%"
className="absolute inset-0"
>
<PieChart.Slice />
</PieChart>
<View
pointerEvents="none"
className="absolute inset-0 items-center justify-center"
>
<Text className="text-3xl font-bold text-foreground">4.5K</Text>
</View>
</View>import { Card } from 'heroui-native';
import { PieChart, type PieChartLabelSlice } from 'heroui-native-pro';
import { View } from 'react-native';
const DATA = [
{ name: 'Chrome', value: 62 },
{ name: 'Safari', value: 19 },
{ name: 'Firefox', value: 10 },
{ name: 'Edge', value: 9 },
];
const formatPercent = ({ percent }: PieChartLabelSlice) =>
`${Math.round(percent * 100)}%`;
const formatShare = (value: number) => `${value}%`;
export default function BrowserUsageChart() {
return (
<View className="flex-1 justify-center px-5">
<Card>
<Card.Header>
<Card.Title>Browser Usage</Card.Title>
</Card.Header>
<Card.Body>
<PieChart
data={DATA}
labelKey="name"
valueKey="value"
innerRadius="50%"
startAngle={-90}
animateIn
className="h-[220px]"
>
<PieChart.Slice />
<PieChart.SliceAngularInset strokeWidth={3} />
<PieChart.Label format={formatPercent} />
<PieChart.Tooltip format={formatShare} />
</PieChart>
</Card.Body>
</Card>
</View>
);
}The chart deliberately stays left-to-right in RTL layouts: everything inside the canvas is drawn by Skia in physical coordinates. Pair the chart with a text legend or summary when the values matter to screen reader users.
| prop | type | default | description |
|---|---|---|---|
data | Row[] | - | One row per slice. A new array animates; mutating the same array is not detected. |
labelKey | keyof Row | - | Field holding each slice's label (string or number). |
valueKey | keyof Row | - | Field holding each slice's value; slices share the circle by it. |
colorKey | keyof Row | - | Field holding each slice's color. Rows without one take chart-1 … chart-5. |
innerRadius | number | '${number}%' | 0 | Hole radius in pixels or as a percentage of the radius. 0 draws a full pie. |
startAngle | number | 0 | Start of the first slice, degrees clockwise from 3 o'clock (-90 is 12 o'clock). |
circleSweepDegrees | number | 360 | Degrees the slices share. Negative values run counter-clockwise. |
animateIn | boolean | number | false | Sweeps the slices in on mount; true is 700 ms, a number sets the duration. |
resetKey | unknown | - | Changing it replays animateIn. |
animate | boolean | ChartTransition | true | Data-change animation ({ type: 'timing' | 'spring', ...config }). |
animation | 'disable-all' | - | "disable-all" turns off every animation in the chart. |
selection | { activateAfter?: number } | false | { activateAfter: 100 } | Press-to-inspect; false turns it off. |
onSelect | (event: { index: number; row: Row } | null) => void | - | Called on the JS thread when the pressed slice changes; null when it ends. |
className | string | - | Root view class. Set the size here. |
children | ReactNode | - | Chart parts. |
| prop | type | default | description |
|---|---|---|---|
dimOpacity | number | 0.4 | Opacity of the other slices while one is pressed. 1 disables dim. |
| prop | type | default | description |
|---|---|---|---|
strokeWidth | number | 2 | Width of each gap in pixels. |
color | string | theme background | Color of the gaps. Match it to what is behind the chart. |
| prop | type | default | description |
|---|---|---|---|
font | SkFont | null | chart axis font | Skia font (11 px system font by default). |
color | string | theme accent-foreground | Text color. |
radiusOffset | number | - | Distance from the center as a share of the radius. Defaults to mid-ring. |
format | (slice: PieChartLabelSlice) => string | slice label | Text of each slice. Receives { index, label, value, percent }. JS thread. |
| prop | type | default | description |
|---|---|---|---|
dataKey | string | root valueKey | Field whose value the default content shows. |
format | (value: number) => string | - | Formats the default value. Runs on the JS thread. |
placement | 'top' | 'bottom' | away from the center | Preferred side of the slice; flips when there is no room. Without it, above the upper half of the chart and below the lower half. |
gap | number | 12 | Space between the anchor point and the tooltip. |
className | string | - | Tooltip view class. Replaces the default pill when children is set. |
children | ReactNode | - | Custom content (ChartTooltipLabel, ChartTooltipValue). |