Skip to Content
文档

饼图

用于将数据显示为圆形图表的片段

StorybookRecharts

用法

¥Usage

import { Chart, useChart } from "@chakra-ui/charts"
import { Pie, PieChart } from "recharts"
<Chart.Root>
  <PieChart>
    <Pie />
  </PieChart>
</Chart.Root>

示例

¥Examples

标签内部

¥Label inside

Pie 中渲染 recharts 中的 LabelList,以在饼图中显示标签。

¥Render the LabelList from recharts inside the Pie to display the label inside the pie chart.

<Pie>
  <LabelList dataKey="name" position="inside" />
</Pie>

标签外部

¥Label outside

label 属性传递给 Pie 组件,即可在饼图外部显示标签。

¥Pass the label prop to the Pie component to display the label outside the pie chart.

<Pie labelLine={false} label={({ name, value }) => `${name}: ${value}`}>
  {/* ... */}
</Pie>

移除描边

¥Remove Stroke

stroke 属性设置为 none 可移除饼图中的描边。

¥Set the stroke prop to none to remove the stroke from the pie chart.

图例

¥Legend

渲染 Chart.Legend 组件以显示饼图的图例。

¥Render the Chart.Legend component to display a legend for the pie chart.

点标签

¥Point Label

以下是如何添加点标签的示例。

¥Here's an example of how to add point labels.

起始角度

¥Start Angle

startAngleendAngle 属性设置为饼图所需的起始和结束角度。

¥Set the startAngle and endAngle props to the desired start and end angles for the pie chart.

<Pie startAngle={180} endAngle={0}>
  {/* ... */}
</Pie>

Previous

折线图

Next

雷达图