2015-10-19 271 views
1

我正在使用Plotly编写网页。问题是,当我使用Plotly_onclick事件时,似乎有什么问题。 具体来说,当我点击使用我的鼠标,它不反应。当我点击使用笔记本电脑的触摸板时,即按下触摸板时,它也不反应。只有当我大量触碰我的触控板时,才会发生反应。 我无法处理这个问题。有谁知道如何解决它?Plotly.js单击事件

点击事件的代码是在这里:

.on('plotly_click', function (event, eventdata) { 

     var point = eventdata.points[0]; 

     var traceColor = point.fullData.marker.color, 
      newAnnotation = { 
       x: point.xaxis.d2l(point.x), 
       y: point.yaxis.d2l(point.y), 
       ax: 0, 
       ay: -50, 
       arrowhead: 6, 
       bgcolor: 'rgba(255,255,255,0.75)', 
       arrowcolor: traceColor, 
       font: {color: traceColor}, 
       text: point.data.name + ':' + point.y + 'on ' + point.x 
      }, 
      newIndex = (rangePlot.layout.annotations || []).length; 
      console.log(newIndex); 

     var TextFromUser = {name: point.data.name, time: point.x, value: point.y}; 

     if(TextFromUser['time'].length==10) 
     { 
      TextFromUser['time']=TextFromUser['time']+' 00:00'; 
     } 
     else if(TextFromUser['time'].length==13) 
     { 
      TextFromUser['time']=TextFromUser['time']+':00'; 
     } 
     else; 



     if (newIndex) { 

      var foundCopy = false; 
      rangePlot.layout.annotations.forEach(function (ann, sameIndex) { 
       if (ann.text === newAnnotation.text) { 
        Plotly.relayout(rangePlot, 'annotations[' + sameIndex + ']', 'remove'); 
        foundCopy = true; 
       } 
      }); 
      if (foundCopy) return; 
     } 

     Plotly.relayout(rangePlot, 'annotations[' + newIndex + ']', newAnnotation); 

    }) 

回答

0

例如裁判: https://plot.ly/javascript/click-events/

代码:

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

它有一些泻湖,但它是一个开始的事件火...