- https://plot.ly/javascript/plotlyjs-events/#click-event
- https://plot.ly/javascript/click-events/#click-event-data
- https://community.plot.ly/t/documentation-on-plotly-hover-and-click-events/833
I am having trouble binding the plotly_click event to my bar chart in plotly.js. From all of the documentation / posts I've seen (see links above), the data passed from the event to the callback should be structured like the following:
{
points: [{
curveNumber: 2, // index in data of the trace associated with the selected point
pointNumber: 2, // index of the selected point
x: 5, // x value
y: 600, // y value
data: {/* */}, // ref to the trace as sent to Plotly.plot associated with the selected point
fullData: {/* */}, // ref to the trace including all the defaults
xaxis: {/* */}, // ref to x-axis object (i.e layout.xaxis) associated with the selected point
yaxis: {/* */} // ref to y-axis object " "
}, {
/* similarly for other selected points */
}]
}
However, when my click event is triggered, I am see the following:
{
currentTarget: div#containers-per-month-chart.js-plotly-plot
data: undefined
delegateTarget: div#containers-per-month-chart.js-plotly-plot
handleObj: {type: "plotly_click", origType: "plotly_click", data: undefined, handler: ƒ, guid: 37, …}
isTrigger: 3
jQuery111208711647541870211: true
namespace: ""
namespace_re: null
result: undefined
target: div#containers-per-month-chart.js-plotly-plot
timeStamp: 1572448651720
type: "plotly_click"
__proto__: Object
}
Does anybody know why the json I am receiving is different from what is documented? I am creating my chart and binding the click event as the document shows.
Here is how I am creating my chart:
Plotly.newPlot('my-plotly-bar-chart', data, layout, config);
Here is how I am binding the click event:
$('#my-plotly-bar-chart').on('plotly_click', function (data) {
console.log(data)
});
(I figured out my issue in the middle of writing this question, but in the spirit of Self Answering to Document for others I figured I would still post the question and answer this myself.)