Search code examples
javascriptreactjsamchartsamcharts4

Amcharts 4 : Disable single legend item programmatically


I just need to know how to disable a single legend item programmatically on chart reload (disable means: legend is shown greyed out and its linked curve is hidden), as I need to reload a chart with some new data using some back and forward arrows, but still need to remember the user preference or the state of legend items (on/off)


Solution

  • Thanks @xorspark that's really it, it's about controlling the series not legend.

    It happened to work specifically with the appeared or inited events, not shown event as it seemed to be, like this:

    series.events.on("inited", () => {
      reactState ? series.show() : series.hide();
    });
    

    inited event even works better, as disabled legends will not show a glimpse of their color on the curve when using appeared.