score:2
Your problem is not so much related to the mouseover event listener, but more to the way you bind data to your path; you don't do a proper data join.
Read more about data joins: http://bost.ocks.org/mike/join/
The following example is using divs instead of paths, but the principle is the same. See working example at: http://jsfiddle.net/RghQn/
var data = ['a', 'b', 'c'];
d3.select("body").selectAll("div")
.data(data)
.enter().append("div")
.text(String)
.on("mouseover", function(d,i) {
console.log("mouseover!");
// d: bound datum to DOM element
console.log("d: ", d);
// i: index of the selection
console.log("i: ", i);
// this context: the current DOM element
console.log(d3.select(this).text());
});
See also the API docs section about event listeners: https://github.com/mbostock/d3/wiki/Selections#wiki-on
selection.on(type[, listener[, capture]])
Adds or removes an event listener to each element in the current selection, for the specified type. The type is a string event type name, such as "click", "mouseover", or "submit". The specified listener is invoked in the same manner as other operator functions, being passed the current datum d and index i, with the this context as the current DOM element. To access the current event, use the global d3.event.
EDIT
I know realize I misunderstood your question. You have one path and want to get information about the path coordinates at the location of the mouse.
There is not straightforward. You can see how Mike did it in the following example: http://bl.ocks.org/3902569
score:6
@nautat has the right answer in his edit, but I'd like to expand on it because for whatever reason the blocks examples rarely have comments and can be like unfolding someone else's origami.
This is the relavant part from http://bl.ocks.org/3902569 ... comments along the way are mine
// define a function for mouse move
// this function is wired up to the visualization elsewhere with .on('mousemove', fn)
function mousemove() {
// using the x scale, in this case a d3 time scale
// use the .invert() function to interpolate a date along the scale
// given the x-coordinates of the mouse
var x0 = x.invert(d3.mouse(this)[0]),
// using the interpolated date, find an index in the sorted data
// this would be the index suitable for insertion
i = bisectDate(data, x0, 1),
// now that we know where in the data the interpolated date would "fit"
// between two values, pull them both back as temporaries
d0 = data[i - 1],
d1 = data[i],
// now, examine which of the two dates we are "closer" to
// to do this, compare the delta values
d = x0 - d0.date > d1.date - x0 ? d1 : d0;
// move the "focus" element into position
// we find the X and Y values for the new position using the x and y scales
// using the closest data point to the mouse
focus.attr("transform", "translate(" + x(d.date) + "," + y(d.close) + ")");
// set the text of the "focus" element to be the value of the element selected
focus.select("text").text(formatCurrency(d.close));
}
Source: stackoverflow.com
Related Query
- Using Javascript D3 library, how can I determine mouse position in data set of an area element on mousemove event?
- How can I position rotated x-axis labels on column chart using nvd3?
- Using d3.js, how can I display data faster on my chart?
- How to set the Origin (drag.origin) for drag behavior in d3 JavaScript library
- How can I show a graph using d3 force layout with initial positions set and no movement at all?
- How can I set the position of a drop down list with D3.js?
- How to iterate over data in JSON file using D3 javascript
- Using Javascript D3 library, how replace data in selection of rects?
- In a d3 scatterplot using data from a csv file, how do i draw lines connecting related points when the mouse is over a point?
- In d3.js, while importing csv files using a row conversion, how can I "slice" the data to only include a range of rows?
- How can I specify a d3.js selector using values from a data object?
- In D3 I'm assigning a colour to a data category using d3.scale.ordinal(). How can I assign it based on value of x-axis?
- How to determine a SVG shape based off of data using d3.js
- How can I group data to be filtered without losing crossfilter functionality using dc.js?
- How can i set default color on element after mouse out D3
- How can we Sum the data of .csv file columnwise using d3.js
- How can I dynamically generate javascript within a script tag using jade and express
- How can I get the source code from a page using javascript
- How can I draw chart between 2 categories (strings) using recharts library
- How can I parse csv data from a javascript array of strings for use in d3 graphs
- How can i use the data from Hbase to visualize using d3.js
- How can I find the frequency of each member in my data set
- how do I set up a grouping query on the server side. I want set up the query so I can use it for a pie chart in front end, using d3js
- How to convert this data to csv using Nodejs/ JavaScript
- How much data can be visualized by a brower using JSON file?
- How can I set max value(range) for y-axis and bar width of a bar chart using nvd3.js
- How can I add an image as the fill for a circle dynamically in javascript using d3
- How can create a table with using filter on csv data
- how can set customize color to pie chart using D3.js?
- How can we create multi column table using multi array JSON using d3 and crossfilter javascript frameworks
More Query from same tag
- Points change position on zoom in D3 scatterplot
- d3.js - Pie chart with interactive legend hover problems
- D3 Donut chart: Display Value on segment hover
- D3 the x axis positions in wrong way
- D3 seemingly updating wrong SVG element
- Append element on d3 dragstart
- d3.js Tree Node Layout remove root node
- Change starting point of alongPath animation
- D3v4 inserting new nodes
- DC.js - trigger elastic resize when criteria are met
- nvd3 - multiBarChart: how to log scale y axis
- d3. Calling a csv url from an array javascript
- D3.js Plotting Multiple Data Sets from Separate Files
- D3.js line chart grid issue
- D3 Topojson Adding Name Property to FeatureCollection
- d3js - SVG circle in smooth perpetual motion
- How to dynamically translate an SVG group in D3.js?
- D3Js line graphs - align data points with ticks
- Formatting bar graph for integers developed using d3.js
- Is a horizontal scroll bar for graphs available on Bokeh?
- Style of axis tick labels in d3.js
- how exactly does event handling and filtering work in dc.js?
- tree.nodes(root).reverse(); returns too many nodes
- 3D Pie Chart using d3.js
- is there a way to convert svg <line> to svg <path> in illustrator?
- Dynamic update to y-axis of a zoomable area chart
- What does the statement d3.select(#toolTip) do? I am trying to assign the value returned to a var in js.
- Determine the bucket to which a number belongs to
- How can i Show values over the NVD3 historical bar?
- How to add a symbol to a group depending on its data