# React Native Pie & Donut Chart (Pro)

> React Native pie and donut charts for iOS, Android and the web: slices that sweep in and turn to new shares, half donuts, outside percent labels, the slice under the finger in the donut's hole, legend toggles that leave a slice out, and a screen-reader summary of each part's share.

# Pie & Donut chart Pro

Parts of a whole. The legend names each slice with its share, and pressing a legend item leaves that slice out (the rest re-share the whole). The slice under the finger or pointer lifts out; in a `DonutChart` the hole shows it, and the total otherwise. Slices sweep open on mount and turn to new shares when the data changes. `startAngle={-90} endAngle={90}` draws a half donut.

```tsx
import { DonutChart, PieChart } from '@patine-ui/pro';
```

## Live data

```tsx live
import { useState } from 'react';
import { View } from 'react-native';
import { Button } from 'patine-ui';
import { DonutChart } from '@patine-ui/pro';

const browsers = ['Chrome', 'Safari', 'Firefox', 'Edge', 'Other'];
const roll = () => browsers.map((browser) => ({ browser, visitors: 40 + Math.round(Math.random() * 260) }));

export default function Example() {
  const [data, setData] = useState(roll);
  return (
    <View style={{ width: 360, gap: 8 }}>
      <Button size="sm" variant="outline" onPress={() => setData(roll())} style={{ alignSelf: 'flex-end' }}>Shuffle</Button>
      <DonutChart
        data={data}
        nameKey="browser"
        valueKey="visitors"
        centerLabel="Visitors"
        valueFormat="compact"
        height={220}
        accessibilityLabel="Visitors by browser"
      />
    </View>
  );
}
```

## Example: where the money went

A budgeting app's month: each category's share of spending, the total in the hole, and Savings hidden at first so the chart shows only what was spent. Press it in the legend to add it.

```tsx live wide
import { View } from 'react-native';
import { Text } from 'patine-ui';
import { DonutChart } from '@patine-ui/pro';

const SPENT = [
  { category: 'Rent', amount: 1150 },
  { category: 'Groceries', amount: 412 },
  { category: 'Transport', amount: 136 },
  { category: 'Eating out', amount: 248 },
  { category: 'Subscriptions', amount: 64 },
  { category: 'Savings', amount: 500 },
];

export default function Example() {
  return (
    <View style={{ width: '100%', maxWidth: 520, gap: 8 }}>
      <Text weight="semibold">October</Text>
      <DonutChart
        data={SPENT}
        nameKey="category"
        valueKey="amount"
        centerLabel="Spent"
        valueFormatter={(v) => `€${v.toLocaleString()}`}
        defaultHidden={['Savings']}
        showLabels
        height={260}
        accessibilityLabel="Spending by category in October"
      />
    </View>
  );
}
```

## Gallery

### Half donut

```tsx live
import { DonutChart } from '@patine-ui/pro';

const data = [
  { plan: 'Free', users: 5200 },
  { plan: 'Pro', users: 2100 },
  { plan: 'Team', users: 860 },
];

export default function Example() {
  return (
    <DonutChart
      data={data}
      nameKey="plan"
      valueKey="users"
      startAngle={-90}
      endAngle={90}
      innerRadius={0.7}
      centerLabel="Users"
      valueFormat="compact"
      height={180}
      style={{ width: 340 }}
    />
  );
}
```

### Pie with labels

```tsx live
import { PieChart } from '@patine-ui/pro';

const data = [
  { category: 'Rent', spent: 1800 },
  { category: 'Food', spent: 620 },
  { category: 'Transport', spent: 240 },
  { category: 'Fun', spent: 310 },
  { category: 'Savings', spent: 900 },
];

export default function Example() {
  return (
    <PieChart
      data={data}
      nameKey="category"
      valueKey="spent"
      showLabels
      valueFormat="currency"
      legendPosition="top"
      height={240}
      style={{ width: 360 }}
    />
  );
}
```

## Props

The [shared chart props](./charts#shared-props), and:

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `nameKey` | `string` | — | The row field naming each slice. |
| `valueKey` | `string` | — | The row field with each slice's value. Zero, negative and missing values get no slice. |
| `series` | `{ key, label?, color? }[]` | — | Labels and colors, matched to `nameKey`. |
| `innerRadius` | `number` | `0` (pie), `0.62` (donut) | The hole, as a share of the radius. |
| `startAngle` | `number` | `0` | Degrees clockwise from 12 o'clock. |
| `endAngle` | `number` | `360` | `-90` to `90` is a half donut. |
| `padAngle` | `number` | `0.7` | Degrees between slices. |
| `showLabels` | `boolean` | `false` | Each slice's share outside it. |
| `defaultHidden` | `string[]` | — | Slices left out at first; the legend brings them back. |
| `centerLabel` | `string` | — | `DonutChart`: under the total. |
| `centerValue` | `string` | the total | `DonutChart`: in the hole instead of the total, e.g. `'730K'`. |
