2017-03-16 19 views
1

私のプロットチャートにカーソルを合わせると、x軸の値が必要です。 plotly docs(https://plot.ly/javascript/hover-events/)によると、ホバーイベントコールバックには、x値を取得するフィールド「ポイント」が含まれている必要があります。Plotly JS:ホバーイベントにポイントが含まれていません

しかし、この基本的な例を見ると、コールバックにフィールド「ポイント」が含まれていないことがわかります。また、 "データ" のような他のフィールドは未定義です:

<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 } }); 
}) 

ためにこのフィドルを参照してください、それを自分で試して

HTML: https://jsfiddle.net/c1kt3r82/158/

私は間違って何をしていますか?

答えて

2
  • plotly-basicplotly-latestではなく
  • 要素を選択するために、jQueryのを使用して、それは hoverイベントは後に定義する必要が document.getElementById
  • 経由で行うよりも別のオブジェクトを返す使用し、ホバーイベントをサポートしていないようですplot

$(document).ready(function() { 
 

 
    var 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_hover', function(data) { 
 
    console.log(data) 
 
    }); 
 
});
<div id="tester" style="width:600px;height:250px;"></div> 
 
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script> 
 
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
呼び出します

+0

ありがとうございました! :) – ReactiveMax

関連する問題