Question about click event data for legends


Hello everyone. I have a question about or more precisely about .

When running graph.on('plotly_legendclick', function(clickData) { console.log(clickData.layout); console.log(clickData.layout.hiddenlabels); } by clicking on a pie chart legend item and thus hiding it from the plot, I do see a layout object in the console. This layout object contains the array hiddenlabels (as an attribute) with the one label legend item that I’ve hidden. But the next console output is undefined. It doesn’t find hiddenlabels as if it doesn’t exist.

Why is this happening and how can I access the hiddenlabels array in this context properly? Do I have to use .then() ?


Ha I see. plotly_legendclick is triggered before hiddenlabels is updated.

You should listen to plotly_relayout instead:


Interesting! Will try this out tomorrow, thanks a bunch!


@etienne Yes! I managed to achieve my goal by using plotly_relayout. Sadly I have another problem now, because I need to rearrange “plotly legend group titles”, which are hacky annotations, on different counts of labels now. sigh
Thank you very much for your help!

EDIT: I guess setting the font and value color to transparent is the way to go here to keep the height positioning of everything x)…