Hesham Elquerm
Hesham Elquerm

Reputation: 59

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)

Upvotes: 0

Views: 917

Answers (2)

Hesham Elquerm
Hesham Elquerm

Reputation: 59

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.

Upvotes: 0

xorspark
xorspark

Reputation: 16012

You can just call hide on the series associated with that legend marker to hide the series/grey out the marker:

series.hide();

Upvotes: 1

Related Questions