Flot - 检测左键单击和右键单击
我正在使用 Flot 绘制折线图。实时更新,有多个系列。我希望能够检测到图表中各个系列的鼠标左键和右键单击。
目前,我可以检测到鼠标左键单击,但右键单击只会显示浏览器的右键单击菜单。
这是我到目前为止所得到的:
function myClick(event, pos, obj) {
if (!obj) {
return;
}
alert('clicked!');
}
var placeholder = $("#placeholder");
// setup plot
var options = {
...
grid: {clickable: true, hoverable: true},
...
};
var initialData = getMyData();
var plot = $.plot(placeholder, initialData , options);
placeholder.bind("plotclick", myClick);
有没有办法检测图表中一系列的右键单击?
I'm drawing a line graph using Flot. It's updated in real-time and has multiple series. I want to be able to detect left and right mouse clicks on individual series in the graph.
Currently, I can detect a left mouse click, but right-click just brings up my browser's right-click menu.
Here's what I've got so far:
function myClick(event, pos, obj) {
if (!obj) {
return;
}
alert('clicked!');
}
var placeholder = $("#placeholder");
// setup plot
var options = {
...
grid: {clickable: true, hoverable: true},
...
};
var initialData = getMyData();
var plot = $.plot(placeholder, initialData , options);
placeholder.bind("plotclick", myClick);
Is there a way to detect right-clicks on a series in the graph?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 float 源,这不是内置功能。它被编码为仅处理网格上的 mousemove、mouseleave 和 click 事件。如果我是你,我会考虑直接修改 flot 源并用 mousedown 事件替换 click 事件。一旦你这样做了,就应该很容易处理左、右、中点击。
编辑
我意识到这是一个旧答案,但我突然想到了一个想法。解决这个问题的方法是在不修改源代码的情况下使用plothover 来监视鼠标是否位于某个点上,然后将通用的mousedown 处理程序绑定到plot div。
请参阅此处的小提琴。
Looking at the flot source, this is not a built-in feature. It is coded to handle only the mousemove, mouseleave, and click events on the grid. If I were you I would look into modifying the flot source directly and replacing the click event with the mousedown event. Once you do that it should be easy to handle left vs right vs center clicks.
EDITS
I realize this is an old answer but a thought occurred to me. A work around for this, without modifying the source, is to use the plothover to monitor whether the mouse is over a point and then bind a generic mousedown handler to the plot div.
See fiddle here.