gpt4 book ai didi

javascript - 通过单击 AmChart4 使系列隐藏和显示

转载 作者:行者123 更新时间:2023-11-30 14:17:20 25 4
gpt4 key购买 nike

我正在尝试实现 thisAmChart4

单击图例标记仅显示一张图。

它使用 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();
}
})
});

Demo

关于javascript - 通过单击 AmChart4 使系列隐藏和显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53357140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com