Getting Mouse Pointer X and Y cordinates when Mouseover Column Chart

843 views
Skip to first unread message

Praveenkumar Gola

unread,
Mar 19, 2013, 7:23:55 PM3/19/13
to google-visua...@googlegroups.com
Hi,
I drawn a Column Chart and i want to display a div when  mouseover a column,  for this i needed a X and Y coordinates.
i know i can trigger mouseover event for columnchart which i did but i cannot get the e.pageX and e.pageY values with this event, is there way to get mouse co ordinates.

Thanking in advance.


asgallant

unread,
Mar 19, 2013, 7:49:36 PM3/19/13
to google-visua...@googlegroups.com
The mouseover events in the API don't work the same as HTML mouseover events.  To get the location of the mouse pointer, you will need to keep track of it some other way.  Here's one way:

var mouse = {x: null, y: null};
document.onmousemove = function (e) {
    mouse.x = e.pageX;
    mouse.y = e.pageY;
}

Check the values in "mouse" when you need them.

Praveenkumar Gola

unread,
Mar 19, 2013, 8:44:04 PM3/19/13
to google-visua...@googlegroups.com
Thanks for replying soon.
the below is my scenario i trigger this event when mouseover a column in column chart
div in my element to show when mouseover and below is mycode and its not working


var mouse = {x: null, y: null};
document.onmousemove = function (e) {
    mouse.x = e.pageX;
    mouse.y = e.pageY;
}
google.visualization.events.addListener(chart, 'onmouseover', mouseover);

function mouseover(e)
{
 
 $('#div').show(1000);
 $('#div').offset({left:mouse.Y,top:mouse.Y});

}

asgallant

unread,
Mar 19, 2013, 9:32:46 PM3/19/13
to google-visua...@googlegroups.com
You need to access mouse.x and mouse.y, not mouse.X or mouse.Y.  See an example here: http://jsfiddle.net/asgallant/W7RVP/
Reply all
Reply to author
Forward
0 new messages