我需要帮助获取堆叠条形图中每个矩形的X和Y坐标。
我正在创建一个新的矩形,并希望它在堆叠条形图上方右侧的悬停矩形上创建。
这是我定义的鼠标移动函数,问题在于它只给出堆叠条形图中第一个矩形的y值。
function movein() { var allRect = d3.selectAll("rect") // .transition() // .duration(300) .attr("opacity", 0) .attr("display", "none")
d3.select(this) .attr("opacity", 1) .attr("display", "block")
d3.select('.g') .append("rect") .attr("y", function(d) { return y(d.y1); }) .attr("x", 100) .attr("height", 50) .attr("width", 0) .attr("z-index", 1000) .attr("class", "rect-sec")
d3.select('.rect-sec') .transition() .duration(300) .attr("width", 200) };
请有人帮助获取每个矩形的X和Y坐标。
这是我参考的链接中的堆叠条形图。
mouseover
函数,我会像这样调用它.on("mouseover", movein)
。您需要整个代码吗? - Unknown Userd3.select(this).attr("x")
来获取当前选中的rect
元素的x坐标。 - Lars Kotthoff.attr("text-anchor", "middle")
。 - Lars Kotthoff