Retrieve customdata of element clicked on (JS)

I want to show additional data in a div relevant to the bar the user clicks on in my bar chart (plotly.js). I’ve added the information as customdata to the data array, but I can’t find anything in the DOM element that is being returned on click. I can’t find anything to even hint at how I’d go about this, except for the plotly_onclick handler, but just like this person here, it doesn’t return anything. Any pointers would be helpful…

Edit - I’ve added a click listener event to the parent div, and when I click on a bar, the event.target returns the entire rectangle containing all bars - not the actual bar clicked on. So also not really what I need at all…

I leave you this example that when you click on a bar, it shows you in the console the name of the group of bars and the index of the bar that was clicked on.

1 Like