Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

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)