Plotly JS:悬停事件不包含点

时间:2017-03-16 13:52:36

标签: javascript hover plotly

将鼠标悬停在我的阴谋图表上时,我需要x轴值。 根据情节文档(https://plot.ly/javascript/hover-events/),悬停事件回调应该包含字段" points"从中我应该得到x值。

但是如果你看一下这个基本的例子,你会发现回调不包含字段" points"。还有其他字段,如"数据"未定义:

HTML

<div id="tester" style="width:600px;height:250px;"></div>

JS

$(document).ready(function(){

   var tester = $('#tester');

   tester.on('plotly_hover', function(data){
     console.log(data)
   });

   Plotly.plot( 'tester', [{
       x: [1, 2, 3, 4, 5],
       y: [1, 2, 4, 8, 16] }], { 
       margin: { t: 0 } } );
})

看到这个小提琴,以便自己尝试: https://jsfiddle.net/c1kt3r82/158/

我做错了什么?

1 个答案:

答案 0 :(得分:2)

  • Z似乎不支持悬停事件,请改用<{1}}
  • 当使用jQuery选择元素时,它会返回一个不同于通过Z
  • 执行的对象
  • 调用B
  • 后需要定义plotly-basic个事件

plotly-latest
document.getElementById