我正在尝试在我的绘图图表上创建一个 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 :
最佳答案
在你的 fiddle 中,你正在使用 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>
关于javascript - plotly javascript。 'plotly_click' gets on 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40763606/