Flot - Detect Left-click And Right-click
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. C
Solution 1:
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.
var currentPoint = null;
$("#placeholder").bind("plothover", function (event, pos, item) {
if (item) {
currentPoint = item;
} else {
currentPoint = null;
}
});
$('#placeholder').mousedown(function(event) {
if (currentPoint)
{
switch (event.which) {
case1:
alert('Left mouse button pressed on ' + currentPoint.series.label);
break;
case2:
alert('Middle mouse button pressed on ' + currentPoint.series.label);
break;
case3:
alert('Right mouse button pressed on ' + currentPoint.series.label);
break;
default:
alert('You have a strange mouse on ' + currentPoint.series.label);
}
}
});
See fiddle here.
Post a Comment for "Flot - Detect Left-click And Right-click"