Show data on mouseover of circle

前端 未结 5 1290
我寻月下人不归
我寻月下人不归 2020-11-22 10:05

I have a set of data that I am plotting in a scatter. When I mouseover one of the circles I would like it to popup with data (like x, y values, maybe more). Here is what I

5条回答
  •  Happy的楠姐
    2020-11-22 10:08

    I assume that what you want is a tooltip. The easiest way to do this is to append an svg:title element to each circle, as the browser will take care of showing the tooltip and you don't need the mousehandler. The code would be something like

    vis.selectAll("circle")
       .data(datafiltered).enter().append("svg:circle")
       ...
       .append("svg:title")
       .text(function(d) { return d.x; });
    

    If you want fancier tooltips, you could use tipsy for example. See here for an example.

提交回复
热议问题