Skip to Content
文档

圆环图

用于将数据显示为类似甜甜圈的圆形图表的片段

StorybookRecharts

用法

¥Usage

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

示例

¥Examples

点标签

¥Point Label

要在图表上显示点标签,请使用 recharts 中的 PointLabel 组件。

¥To display a point label on the chart, use the PointLabel component from recharts.

起始和结束角度

¥Start and End Angle

自定义 <Pie> 组件的 startAngleendAngle 属性可以创建部分甜甜圈。

¥Customizing the startAngle and endAngle prop of the <Pie> component can create partial donuts.

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

角度填充

¥Angle Padding

要在段之间添加一些空间,请使用 paddingAngle 属性。

¥To add some space between the segments, use the paddingAngle prop.

专业提示:要将各段的角设为圆角,请使用 cornerRadius 属性。

分离段

¥Detached Segment

要创建活动段缩放并与其他段分离的效果,请使用 activeIndex 属性和 activeShape 属性。

¥To create an effect where the active segment is scaled and detached from the rest of the segments, use the activeIndex prop and the activeShape prop.

<Pie
  innerRadius={60}
  outerRadius={100}
  activeIndex={0}
  activeShape={<Sector outerRadius={120} />}
/>

居中文本

¥Centered Text

使用 Chart.RadialText 组件在图表上显示居中文本,并附带可选描述。

¥Use the Chart.RadialText component to display a centered text on the chart with an optional description.

<Label
  content={({ viewBox }) => (
    <Chart.RadialText viewBox={viewBox} title={1200} description="users" />
  )}
/>

Previous

条形片段

Next

折线图