File size: 1,615 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
---
title: Pie Chart
description: Used to display data as segments of a circular chart
links:
storybook: charts-pie-chart--basic
recharts: https://recharts.org/en-US/api/PieChart
---
<ExampleTabs name="charts/pie-chart-basic" />
## Usage
```tsx
import { Chart, useChart } from "@chakra-ui/charts"
import { Pie, PieChart } from "recharts"
```
```tsx
<Chart.Root>
<PieChart>
<Pie />
</PieChart>
</Chart.Root>
```
## Examples
### Label inside
Render the `LabelList` from `recharts` inside the `Pie` to display the label
inside the pie chart.
```tsx
<Pie>
<LabelList dataKey="name" position="inside" />
</Pie>
```
<ExampleTabs name="charts/pie-chart-with-label-inside" />
### Label outside
Pass the `label` prop to the `Pie` component to display the label outside the
pie chart.
```tsx
<Pie labelLine={false} label={({ name, value }) => `${name}: ${value}`}>
{/* ... */}
</Pie>
```
<ExampleTabs name="charts/pie-chart-with-label-outside" />
### Remove Stroke
Set the `stroke` prop to `none` to remove the stroke from the pie chart.
<ExampleTabs name="charts/pie-chart-no-stroke" />
### Legend
Render the `Chart.Legend` component to display a legend for the pie chart.
<ExampleTabs name="charts/pie-chart-with-legend" />
### Point Label
Here's an example of how to add point labels.
<ExampleTabs name="charts/pie-chart-with-point-label" />
### Start Angle
Set the `startAngle` and `endAngle` props to the desired start and end angles
for the pie chart.
```tsx
<Pie startAngle={180} endAngle={0}>
{/* ... */}
</Pie>
```
<ExampleTabs name="charts/pie-chart-with-start-angle" />
|