svg - Using Javascript D3 library, how can I determine mouse position in data set of an area element on mousemove event? -
I am trying to set up a tooltip for the area path that I have created in all the arguments in the Mausomov event handler Passed, and I'm just getting a full data set of 0, 0. As far as I can see, there is nothing to indicate to my index the data. The "this" reference is also the SVG path element, but nothing is useful, even d3.select (saw), and I did not get the index anywhere. Is there a way to decide which data is my mouse?
Look around I got the reference of D.Mouse (this), and it gives me X / Y coordinates, but how do I map it back to the data point in the data set?
My goal set is to have a tooltip to display some meta-data related to that particular data point.
Here are some code snippets as requested:
var field = d3.svg.area (). Interpolate ("Monoton"). X (function (D) {return (scale (d.date));}) .00 (height-padding.bottom). Y1 (function (d) {return (scale (y.cc)}}; ("clip-path", "url (#clip)") .attr ('fill', '' '' Url #) .attr ('title', 'path') .on ('mousemove', function); console.log (arguments); console.log (d3.select (this)); Console Log (d3.mouse (this));});
Your problem mice events Not much is related to the listener, but in addition to the way you tie data in your way; you do not include a proper data.
Read more about the data: < P> Divs instead of the following example paths Examples of work are:
var data = ['a', 'b', 'c']; d3.select ("body "Select" ("div") .Data (data) .enter () .Append ("div") .text (string) .on ("mouseover", function (d, i) {console.log ("mouseover ! "); // D: Left Element DOM Element Console.log (" D: ", D); //: Selecting the Console Console.Lug (" I: ", I); // This Reference: Current DOM element console.log (d3.select (this) .text ());}); One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? See the API documentation section about event listeners:
Selection. On (type [, listener [Capture]])
Adds or removes each element in an existing list to an event listener for the specified selection. Type is the name of a string event type, such as "click", "mouseover", or "submit". The specified listener is implemented in the same manner as other operator functions, the current Dietum D and Index I are being passed as the current dom element with this reference. To reach the current event, the Global D3 Use the event.
Edit I know I misinterpret your question. You have a way and want to get information about path coordinates instead of the mouse.
There is no straightforward you can see how Mike did in the following example:
Comments
Post a Comment