通过单击 AmChart4 使系列隐藏和显示
Make Series hide and show by clicking on AmChart4
我正尝试在 AmChart4
上实施 this
单击图例标记仅显示一张图表。
它使用 clickMarker
/ clickLabel
但是,AmChart4 没有这些 属性。
所以我可以根据这个得到图例点击事件page
chart.legend.itemContainers.template.events.on("hit", function(ev) {
console.log("Clicked on", ev.target);
console.log(chart);
});
现在我怎样才能得到系列图表和hide/show??
您可以从 ev.target.dataItem.dataContext.name
中获取系列名称,该名称在同一页面的下方进行了说明。您可以使用它并循环遍历图表系列数组并根据需要在 matching/non-matching 系列上调用 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();
}
})
});
我正尝试在 AmChart4
单击图例标记仅显示一张图表。
它使用 clickMarker
/ clickLabel
但是,AmChart4 没有这些 属性。
所以我可以根据这个得到图例点击事件page
chart.legend.itemContainers.template.events.on("hit", function(ev) {
console.log("Clicked on", ev.target);
console.log(chart);
});
现在我怎样才能得到系列图表和hide/show??
您可以从 ev.target.dataItem.dataContext.name
中获取系列名称,该名称在同一页面的下方进行了说明。您可以使用它并循环遍历图表系列数组并根据需要在 matching/non-matching 系列上调用 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();
}
})
});