Get single point for multiple trace plots

Hi,

I have a stacked bar chart which has multiple traces. Is it possible to get only one point from the 3 traces (without having to use select and filter)? I know as of now when using hoverData and clickData with multiple traces, it returns an array of all the points. Possibly using the location of the mouse?

Thanks!

do you mean with hovermode = 'closest ?

I meant when I have a stacked bar chart (partial shown) and I mouse over the stack, but I click on the blue trace. Is it possible to get only the data for a single trace? Because so far when I get clickData or hoverData, my points is an array of 3 elements - for all 3 values under that year.

Just as an example of what I hope to achieve, look at this dashboard from San Francisco using Tableau.

https://sfenvironment.org/sf-climate-dashboard

I don’t believe that it is possible to discern which bar was clicked on since plotly.js assumes that all bars were clicked on. However, if you change 'layout': {'hovermode': 'closest'}, then you should be able to click on a single bar and get the event data just for that bar.

Oh! Thank you. This works!

1 Like

so, if understand this correctly, then there’s no way to have hovermode=compare so that the text will show up for all the sections of the bar, and still get the granular data that hovermode=closest would give?

What do you mean by granular data?

I mean that the clickdata only has data for the bar that is clicked

I see. No, I don’t think there is right now. However, it seems like something that would be useful to add. Could you make an issue in plotly.js (https://github.com/plotly/plotly.js) about “adding data to the click event to discern which bar out of several was clicked”? And please refer that issue back to this community discussion and vice versa.

@chriddyp Was an issue ever made for this? Still would like to be in hovermode: x and the clickdata only return information for the closest point.

I don’t think an issue was made, i encourage you to create one and link back here!