【问题标题】:Jquery Flot "plothover" event not workingJquery Flot“plothover”事件不起作用
【发布时间】:2012-04-16 21:15:54
【问题描述】:

我有一个似乎无法追踪的问题。我正在使用 Flot 绘制一些数据,超级简单。我想添加你在这里看到的悬停效果:Flot Example

不幸的是,在任何情况下我都无法触发 'plothover' 事件。这是代码中的一个简短的sn-p:

$.plot($chartArea, eventData, eventOptions);

$chartArea.bind("plothover", function (event, pos, item) {
    console.log('hovering!');
});

您需要在选项对象中设置什么来启用此行为吗?谢谢!

【问题讨论】:

  • 您能否向我们展示您在 jsfiddle 上的代码的可行示例?这样更容易发现问题。
  • 你是对的,但是我一发布这个,我就意识到我忘记了什么,看看我的答案......

标签: javascript jquery html jquery-plugins flot


【解决方案1】:

像个白痴一样,我忘了包含网格选项。查看对象:

eventOptions = {
   points: {
        show: true
    },
    lines: {
        show: true
    },
    grid: { hoverable: true, clickable: true },
    xaxis: {
        min:earliestMessage.timestamp,
        max:currentTime,
        mode:"time",
        ticks:10
    }
};

注意网格参数。这就是缺少的东西。呵呵!

:)

【讨论】:

  • 谢谢,在“plotclick”事件中遇到了同样的问题,直到我意识到我已将 grid clickable 设置为 false!
【解决方案2】:

我不确定您的代码中的 $chartArea 是什么,但让我们试试这样:

var chartArea = $("#placeholder"); // your chart div

$.plot(chartArea, eventData, eventOptions);

$(chartArea).bind("plothover", function (event, pos, item) {
    console.log('hovering!');
});

【讨论】:

  • 对我有用,给出 id 名称和给出元素名称有什么区别。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-05-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-21
  • 2016-03-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多