Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

On click event on plotly

Here is the script I got from https://plot.ly/javascript/click-events/

I put them into a html file

var myPlot = document.getElementById('myDiv'), d3 = Plotly.d3, N = 16, x = d3.range(N), y = d3.range(N).map( d3.random.normal() ), data = [ { x:x, y:y, type:'scatter', mode:'markers', marker:{size:16} } ], layout = { hovermode:'closest', title:'Click on Points' };

Plotly.newPlot(‘myDiv’, data, layout);

myPlot.on(‘plotly_click’, function(data){
var pts = ‘’;
for(var i=0; i < data.points.length; i++){
pts = 'x = ‘+data.points[i].x +’\ny = '+
data.points[i].y.toPrecision(4) + ‘\n\n’;
}
alert(‘Closest point clicked:\n\n’+pts);
});

But my html won’t display anything like that link showed

Strange. Are you getting any console errors?

Not at all! Which is why I am really confused. No error at all1