dim_voly
dim_voly

Reputation: 541

Unbind Click Events in Plotly

I can't seem to unbind the click event when using the plotly library, there doesn't seem to be a function for it. I need to select 4 points on a graph and then I don't need the handler anymore.

The example on the official site binds events but doesn't demonstrate a way to get rid of chart click handlers.

For now I'll be implementing a loop in the one handler and it will just ignore clicks beyond the 4 that I need. Doesn't seem efficient though.

Upvotes: 3

Views: 1941

Answers (2)

SemmZemm
SemmZemm

Reputation: 51

As suggested in https://github.com/plotly/plotly.js/issues/107#issuecomment-279716312 you can use removeListener and removeAllListeners API methods:

graphDiv.removeListener("plotly_click", handler);
graphDiv.removeAllListeners("plotly_click");

Upvotes: 4

sertsedat
sertsedat

Reputation: 3600

I think this should work

Plotly.newPlot('myDiv', data, layout);

You can see added line in js part in Codepen.

Related GitHub issue

Upvotes: 3

Related Questions