7
我想知道是否有人知道使轴线上的标签可点击的方法。现在我的轴产生如下:d3.js使轴线点击可点击
// Add an x-axis with label.
svg.append("g")
.attr("id", "xaxis")
.attr("class", "x axis")
.attr("transform", "translate(" + (margin.left + margin.left_padding) + "," + height + ")")
.attr("text_anchor", "top")
.call(d3.svg.axis().scale(x).orient("bottom"))
.selectAll("text")
.style("text-anchor", "end")
.attr("font-size", "12")
.attr("dx", "-.8em")
.attr("dy", ".15em")
.attr("transform", function(d) {
return "rotate(-45)"
})
// Add a y-axis with label.
svg.append("g")
.attr("id", "yaxis")
.attr("class", "y axis")
.attr("transform", "translate(" + (margin.left + margin.left_padding) + "," + 0 + ")")
.attr("text-anchor", "right")
.call(d3.svg.axis().scale(y).orient("left"))
.selectAll("text")
.attr("font-size", "12")
}
我不知道如何使它可能轴上的每个号/标签有一个onclick事件。
这看起来不错!如果我在执行过程中遇到任何问题,我会通知您。感谢您及时的回复。 – Andrew
你知道为什么click事件只能注册一次吗?我点击其中一个蜱并且执行了clickme功能,但是当我点击其他蜱时,什么都不会发生。 – Andrew
很难说不能看到你的代码。我建议将最基本的点击事件放在他们身上并从那里进行测试。 – ckersch