我正在尝试在我的绘图图表上创建一个 onclick 事件。根据文档,我创建了以下图表:
var graphDiv = document.getElementById('uniqueId');
Plotly.newPlot('uniqueId', charData, layout);
graphDiv.on('plotly_click', function (data) {
var i = 0;
})
但是,当我运行这个时,我收到以下错误:
graphDiv.on is not a function
那么谁能告诉我我做错了什么?
注意我也尝试过使用jquery:
$('#uniqueId').on('plotly_click', function(){})
这不会引发错误,但单击图表时不会调用该函数。
fiddle:
https://jsfiddle.net/c1kt3r82/127/ https://jsfiddle.net/c1kt3r82/127/
在你的小提琴中你正在使用plotly-basic.js
,你需要使用plotly-latest.min.js
得到on
功能。
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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)