我需要使用 React Recharts 制作包含三个部分的饼图。
我有两个问题:
鼠标悬停时,我想在工具提示中显示带有百分比的文本。如何获取工具提示中的百分比值?
在大小更改时,如果饼图中的某些部分太小,那么我需要隐藏标签;如何实现这一目标?
我的示例代码
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)