1

我不确定为什么我的点击方法不起作用。在这个测试中,我希望能够单击图表上的一个圆形节点并显示其编号。悬停在作品上。

我使用的是什么库的点击事件,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"); });
4

1 回答 1

6

您已将事件处理程序附加到 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; });
于 2013-01-15T22:07:16.637 回答