有一个解决方法,它会帮助你。我建议你创建 2 个馅饼:one with rounded corners 和 one with pointed corners。其余所有数据相同
- 对于尖角,使它们的颜色透明,除了索引 0 和长度 - 1
- 对于圆角,执行相反的操作
你会得到这样的输出:
这是相同的 JS 小提琴:https://jsfiddle.net/kmfby50o/
视觉上你会看到你想要什么。对于 onClick 等功能,将其应用于第二个<Pie>。由于它与第一个重叠,因此也将得到处理。
const { PieChart, Pie, Sector, Cell } = Recharts;
const data = [{ name: 'Group A', value: 400 }, { name: 'Group B', value: 300 },
{ name: 'Group C', value: 300 }, { name: 'Group D', value: 200 }];
const COLORS = ['#0088FE', '#00C49F', '#FFBB28', '#FF8042'];
const RADIAN = Math.PI / 180;
const SimplePieChart = React.createClass({
render() {
return (
<PieChart width={800} height={400} onMouseEnter={this.onPieEnter}>
<Pie
data={data}
cx={420}
cy={200}
startAngle={180}
endAngle={0}
cornerRadius={40}
innerRadius={60}
outerRadius={80}
fill="#8884d8"
paddingAngle={-5}
>
{
data.map((entry, index) => <Cell fill={index === 0 || index === data.length - 1 ? COLORS[index % COLORS.length] : 'transparent'} />)
}
</Pie>
<Pie
data={data}
cx={420}
cy={200}
startAngle={180}
endAngle={0}
cornerRadius={0}
innerRadius={60}
outerRadius={80}
fill="#8884d8"
>
{
data.map((entry, index) => <Cell fill={index === 0 || index === data.length - 1 ? 'transparent' : COLORS[index % COLORS.length]} />)
}
</Pie>
</PieChart>
);
}
})
ReactDOM.render(
<SimplePieChart />,
document.getElementById('container')
);
希望对您有所帮助。如有任何疑问,请回复。