Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotly javascript. 'plotly_click' gets on is not a function

I am attempting to create an onclick event on my plotly chart. Following the documentation i have created the following chart:

var graphDiv = document.getElementById('uniqueId');
Plotly.newPlot('uniqueId', charData, layout);
graphDiv.on('plotly_click', function (data) {
    var i = 0;
})

However when i run this i get the following error:

graphDiv.on is not a function

So can anyone tell me what im doing wrong?

Note i have also attempted with jquery:

$('#uniqueId').on('plotly_click', function(){})

This didnt throw an error but the function was not called when clicking the chart.

fiddle:

https://jsfiddle.net/c1kt3r82/127/

like image 593
Marc Rasmussen Avatar asked May 10 '26 19:05

Marc Rasmussen


1 Answers

In your fiddle you are using plotly-basic.js, you would need to use plotly-latest.min.js to get the on functionality.

TESTER = document.getElementById('tester');

Plotly.plot( TESTER, [{
    x: [1, 2, 3, 4, 5],
    y: [1, 2, 4, 8, 16] }], { 
    margin: { t: 0 } } );
    
    TESTER.on('plotly_click', function(data){
    	alert('did you just click on me?!')
    })

/* Current Plotly.js version */
console.log( Plotly.BUILD );
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<div id="tester" style="width:600px;height:250px;"></div>
like image 184
Maximilian Peters Avatar answered May 12 '26 11:05

Maximilian Peters



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!