我正在尝试实现 this在 AmChart4
单击图例标记仅显示一张图。
它使用 clickMarker
/clickLabel
但是,AmChart4 没有这些属性。
所以我可以根据这个page得到图例点击事件
chart.legend.itemContainers.template.events.on("hit", function(ev) {
console.log("Clicked on", ev.target);
console.log(chart);
});
现在如何获取图表系列并隐藏/显示?
最佳答案
您可以从 ev.target.dataItem.dataContext.name
中获取系列名称,该名称在同一页面的下方进行了说明。您可以使用它并循环遍历图表系列数组,并根据需要在匹配/不匹配系列上调用 show()
或 hide()
,类似于 v3 演示:
chart.legend.itemContainers.template.events.on("hit", function(ev) {
var selectedSeries = ev.target.dataItem.dataContext.name;
chart.series.each(function(series) {
if (series.name === selectedSeries) {
series.show();
}
else {
series.hide();
}
})
});
关于javascript - 通过单击 AmChart4 使系列隐藏和显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53357140/