D3和鼠标事件,点击测试不工作

D3 and mouse events, click test not working

本文关键字:测试 工作 鼠标 事件 D3      更新时间:2023-09-26

我不知道为什么我的点击方法不工作。在这个测试中,我希望能够单击图形上的一个圆形节点并显示其编号。把鼠标悬停在上面有点像。

我使用什么库的点击事件,D3?Jquery吗?正常JS ?

最后我想让工具提示当我把鼠标悬停在节点上时,让它们消失当我把鼠标移开

http://jsfiddle.net/ericps/b5v4R/

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

您已经将事件处理程序附加到svg:text元素。我认为你应该把它附加到svg:circle元素:

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