D3.js: Position tooltips using element position, not mouse position?

后端 未结 4 905
滥情空心
滥情空心 2020-12-02 17:13

I\'m using D3 to draw a scatter graph. I would like to show tooltips when the user mouses over each circle.

My problem is that I can append tooltips, but they\'re p

4条回答
  •  萌比男神i
    2020-12-02 17:45

    Found something here that might address your problem even if and have different positioning. This is assuming you have absolute position set for your tooltip.

    .on("mouseover", function(d) {
        var matrix = this.getScreenCTM()
            .translate(+ this.getAttribute("cx"), + this.getAttribute("cy"));
        tooltip.html(d)
            .style("left", (window.pageXOffset + matrix.e + 15) + "px")
            .style("top", (window.pageYOffset + matrix.f - 30) + "px");
    })
    

提交回复
热议问题