是否可以在拖动点时重绘JUMflot?

时间:2014-08-07 17:53:41

标签: javascript jquery flot

标题真的解释了整个事情。我希望系列能够重新绘制,因为我会移动点数。我完全不知道如何实现这样的东西。

1 个答案:

答案 0 :(得分:1)

没有JUMflot的

Here's a quick example,只是直接的flot。基本上它会监视plothover事件并跟踪最后一个悬停项目。如果我们徘徊了一个项目并且我们已经mousedown然后我们拖动并重绘在后续悬停事件上的情节。当我们鼠标移动时,我们当然会停止:

  // a couple of globals to keep track of
  // which point did we last hover
  // which point did we last mousedown on
  var hoverItem = null;
  var dragItem = null;

  // bind the plot hover
  // if we are hovering an item mark it or null
  // if we are dragging an item, insert the new position into the data and redraw plot
  $("#placeholder").bind("plothover", function (event, pos, item) {
    hoverItem = item;
    if (dragItem){
      var data = plot.getData();
      var series = data[dragItem.seriesIndex];
      series.data[dragItem.dataIndex][0] = pos.x;
      series.data[dragItem.dataIndex][1] = pos.y;
      plot.setData(data);
      plot.draw();
    }
  });

  // when we mousedown on plot, which item did we last hover or null
  $( "#placeholder" ).mousedown(function() {
    dragItem = hoverItem;
  });

  // on mouseup we are no longer dragging
  $( "#placeholder" ).mouseup(function() {
    dragItem = null;
  });