【问题标题】:Make Series hide and show by clicking on AmChart4通过单击 AmChart4 使系列隐藏和显示
【发布时间】:2020-01-29 10:15:34
【问题描述】:

我正在尝试在AmChart4 上实现this

通过单击图例标记仅显示一个图表。

虽然它使用clickMarker / clickLabel,但 AmChart4 没有这些属性。

所以我可以根据这个page得到图例点击事件

  chart.legend.itemContainers.template.events.on("hit", function(ev) {
    console.log("Clicked on", ev.target);
    console.log(chart);
  });

现在我怎样才能获得一系列图表并隐藏/显示??

【问题讨论】:

    标签: javascript amcharts


    【解决方案1】:

    您可以从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

    【讨论】:

      猜你喜欢
      • 2013-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多