admin管理员组

文章数量:1289879

I am not sure why my click method is not working. In this test I want to be able to click on one of the circle nodes on the graph and display its number. Hovering over works kind of.

What library's click event am I using, D3? Jquery? normal JS?

ultimately I want to do tooltips when I hover over the nodes, and make them go away when I move the mouse away

/

dots.enter()
    .append("circle")
    //.append("svg:circle")
    .attr("class", "dot")
    .attr("cx", plete_line.x())
    .attr("cy", plete_line.y())
    .attr("r",3.5)
    .append("title")
    .text(function(d){ return dpleted;})
    .on("click", function(d) { alert("hello"); });

I am not sure why my click method is not working. In this test I want to be able to click on one of the circle nodes on the graph and display its number. Hovering over works kind of.

What library's click event am I using, D3? Jquery? normal JS?

ultimately I want to do tooltips when I hover over the nodes, and make them go away when I move the mouse away

http://jsfiddle/ericps/b5v4R/

dots.enter()
    .append("circle")
    //.append("svg:circle")
    .attr("class", "dot")
    .attr("cx", plete_line.x())
    .attr("cy", plete_line.y())
    .attr("r",3.5)
    .append("title")
    .text(function(d){ return d.pleted;})
    .on("click", function(d) { alert("hello"); });
Share Improve this question asked Jan 15, 2013 at 21:58 CQMCQM 44.3k77 gold badges229 silver badges370 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

You've attached the event handler to svg:text element. I think you want to attach it to the svg:circle element:

dots.enter().append("circle")
    .attr("class", "dot")
    .attr("cx", plete_line.x())
    .attr("cy", plete_line.y())
    .attr("r",3.5)
    .on("click", function(d) { alert("hello"); })
  .append("title")
    .text(function(d){ return d.pleted; });

本文标签: javascriptD3 and mouse eventsclick test not workingStack Overflow