How to dynamically show legend labels using plotly JSON chart

I am working with the new Plotly JSON chart and I am wanting to dynamically show x and y axis labels based on what legend labels are turned on. I know there is an event handler for legend click, but beyond that where should I be looking for the list of legends? I thought this would be somewhere in the chart state, but I don’t know if I am looking in the correct place.

It looks from this post (see below), that the list of legends is not exposed (as of 2022).

You could track the currently selected series in a variable outside of Plotly and rerender the axis labels using a transformer to achieve this functionality. I could provide some instructions on how to do that if required.

Thanks

Hey Jon, thanks for reaching out.

That was my first thought was just so save some type of list to state of the originally rendered legends, but I have 10 or so charts, so I would need that many variables, as well as as that many event handlers. But with all that being said, this seems to be the only solution I can see.

1 Like