3

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/

1 Answer 1

4

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>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.