Possible to access div id, plot options, etc. from within plotly_click event?

Hey Folks,
My want is straightforward, or so I thought.

WIthin a plotly_click event, I need to know context about the actual chart that was clicked on. Examples of this are the div id a value I stuffed into the plot options, or anything else that I can know about the grid prior to actual data binding.

Reviewing the contents I see we capture ‘data’ and ‘fullData’, but neither of these seem to know which chart they actually game from.

My use-case is as follows:

  • I am dynamically generating a set of n plotly histograms, and assigning them unique IDs.
  • These unique IDs are currently being set at the div id level, as well as passed as a placeholder value in options.
  • Within .on(‘plotly_click’, function(event){/* Here! */}); I require being able to look up to see which of the dynamically generated grids this came from. The behavior in-application is contingent upon which grid was checked.

After debugging for the last couple of hours, I’ve made little inroads, and wanted to see if this is a solved problem or something that isn’t currently supported at all.

Cheers.

Here’s one solution: http://codepen.io/etpinard/pen/xgpJMj?

1 Like

Thanks, I’d backed myself into a corner incorrectly thinking I couldn’t pack more in with data. The simplicity of your solution has me feeling somewhat silly.

All good. Explicitly passing the graph div id in the event data is great idea which could potentially make its way into the v2 release.

If you have any other suggestions regarding potential event data improvements, please write to us on https://github.com/plotly/plotly.js/issues/168

Cheers!

Hi!

The @etienne solution didn’t work for me but I get a new one with jquery:

var graphicId = $(".trace" + eventData.points[0].data.uid).closest('[id*="your-graphic-id"]');

Hope it helps :-).