Is there a way to retrieve all selected legends?

Is there a way to retrieve all the selected legends in a graph. The intention behind this is, based on the legends, I have to derive different plots. For instance, if you select two legends, then I have to plot the relationship between those two variables. I have binded the plotly legend event, so whenever I click the legend name, the event gets triggered. Unfortunately, I couldn’t get the legend name or names.

Could you clarify what you mean by “legends”. Plotly graph can only have one legend per graph, so I suspect you mean the legend items, like Data and Fit below


Clicking on a legend item change the traces’ visible attribute, so to list all visible traces on the graph, you could do something like:

var gd = document.getElementById(/* id of your graph div */) => trace.visible)

Hi, when we click first time on the legend, I am getting all visible properties as true. though I can see the first legend item is already clicked and hidden. Can you please help out to get the values correctly when first time clicked on legend item.