Tuesday 15 March 2011

visualization - Binding "mouseover" events to points on a line in d3.js -


I would like to get the coordinates of a line point by clicking the line using the following code: <" "" ":" "" "," Y ": <"> "10}, {" x ": 60," y ": 40}, {" x ": 80," y ": 5}, { "X": 100, "y": 60}]; Var line function = d3.svg.line () .x (function (d) {return dx;}). Y (function (d) {return di;}). Interpotate ("linear"); Var svgContainer = d3.select ("body"). Attached ("svg") .attr ("width", 200) .attr ("height", 200); Var lineGraph = svgContainer.append ("Path"). Data ([Line Data]). Etr ("d", line function) //.attr("d ", line function (line data) .attr (" stroke "," blue "(stroke-width", 2) .attr ("fill", " ("Mousudown", function (D) {console.log ({"x": dx, "y": Dy}}});

(I have comments I have updated the code to address, but I still get the "object {x: undefined, y: undefined}")

When I click on the "undefined" line, Remembering?

you kiss The coordinates of the event can be found:

  .on ("mousedown", function () {console.log ({"x": d3.event.x, "y": d3 .event.y});});    

No comments:

Post a Comment