如何在 amCharts5 上限制每个饼图只有一个活动切片?
How to limit only one active slice per pie chart on amCharts5?
我正在尝试在 amCharts v5 上复制此 v4 教程中的饼图行为,但没有成功:
https://www.amcharts.com/docs/v4/tutorials/one-pulled-slice-per-pie-chart/
v4 代码不适用于 v5(也没有出错)。我已经调试了它并循环遍历切片,但是没有更多的“isActive”属性,并且没有找到任何其他类似的属性或方法来获取或设置切片状态。
我已经在官方文档中搜索过,但一无所获。似乎 v5 缺少一些 v4 功能...有人成功地限制每个图表只选择 1 个切片吗?
提前致谢。
来自官方 amCharts 教程“One pulled slice per pie series”:
... so whenever a slice is pulled out, it becomes "active" (it's
"active"
setting is set to true
). And vice versa, setting it to
false
will make the slice pop back into its place.
Also, when a slice (or any other object for that matter) is
clicked/tapped, it generates a "click"
event. If there's an event
handler defined, it is executed.
Let's use these two bits of code to implement our task:
series.slices.template.events.on("click", function(ev) {
series.slices.each(function(slice) {
if (slice != ev.target && slice.get("active")) {
slice.set("active", false);
}
})
});
CodePen 示例:
https://codepen.io/team/amcharts/pen/dyZzQLJ
我正在尝试在 amCharts v5 上复制此 v4 教程中的饼图行为,但没有成功:
https://www.amcharts.com/docs/v4/tutorials/one-pulled-slice-per-pie-chart/
v4 代码不适用于 v5(也没有出错)。我已经调试了它并循环遍历切片,但是没有更多的“isActive”属性,并且没有找到任何其他类似的属性或方法来获取或设置切片状态。
我已经在官方文档中搜索过,但一无所获。似乎 v5 缺少一些 v4 功能...有人成功地限制每个图表只选择 1 个切片吗?
提前致谢。
来自官方 amCharts 教程“One pulled slice per pie series”:
... so whenever a slice is pulled out, it becomes "active" (it's
"active"
setting is set totrue
). And vice versa, setting it tofalse
will make the slice pop back into its place.Also, when a slice (or any other object for that matter) is clicked/tapped, it generates a
"click"
event. If there's an event handler defined, it is executed.Let's use these two bits of code to implement our task:
series.slices.template.events.on("click", function(ev) {
series.slices.each(function(slice) {
if (slice != ev.target && slice.get("active")) {
slice.set("active", false);
}
})
});
CodePen 示例: https://codepen.io/team/amcharts/pen/dyZzQLJ