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

后端 未结 4 912
滥情空心
滥情空心 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条回答
  •  情歌与酒
    2020-12-02 17:40

    I'm new to D3 so this may not work for scatterplots... but found it seems to work for Bar charts... where v1 and v2 are the values being plotted.. and it seems to look up the value from the data array.

    .on("mouseover", function(d) {
                      divt .transition()
                          .duration(200)
                          .style("opacity", .9);
                      divt .html(d.v1)
                          .style("left", x(d.v2)+50 + "px")
                          .style("top",y(d.v1)+ "px");})
    

提交回复
热议问题