小编Vij*_* Jp的帖子

Recharts Piechart - 有条件地在饼图的每个部分上显示标签

我需要使用 React Recharts 制作包含三个部分的饼图。

我有两个问题:

  1. 鼠标悬停时,我想在工具提示中显示带有百分比的文本。如何获取工具提示中的百分比值?

  2. 在大小更改时,如果饼图中的某些部分太小,那么我需要隐藏标签;如何实现这一目标?

我的示例代码

const {PieChart, Pie, Sector} = Recharts;
const data = [{name: 'Group A', value: 400}, {name: 'Group B', value: 300},
                  {name: 'Group C', value: 300}, {name: 'Group D', value: 200}]; 
function renderCustomToolTip({active, label, payload}) {
  return(
  <div>
    <p> payload[0].label </p>
// need to add percentage value in tooltip
  </div>
);
}
class PieChart extends from React.Component{
    constructor() {
        super(props);
        this.state = {
            activeIndex: 0
        }
    }
    onPieEnter(data, index) {
        this.setState({
          activeIndex: index,
        }); …
Run Code Online (Sandbox Code Playgroud)

reactjs recharts

5
推荐指数
1
解决办法
5999
查看次数

标签 统计

reactjs ×1

recharts ×1