whitebear
whitebear

Reputation: 12433

Make Series hide and show by clicking on AmChart4

I am trying to implement this on AmChart4

Showing only one graph by clicking legend marker.

It uses clickMarker / clickLabel though, AmChart4 doesn't have these property.

So I can get legend click event according to this page

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

And now how can I get the series of charts and hide/show??

Upvotes: 1

Views: 840

Answers (1)

xorspark
xorspark

Reputation: 16012

You can get the series name from ev.target.dataItem.dataContext.name, which is documented further down in the same page. You can use that and loop through the chart series array and call show() or hide() as needed on matching/non-matching series, similar to the v3 demo:

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

Upvotes: 2

Related Questions