Show data on mouseover of circle

前端 未结 5 1305
我寻月下人不归
我寻月下人不归 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条回答
  •  爱一瞬间的悲伤
    2020-11-22 10:21

    You can pass in the data to be used in the mouseover like this- the mouseover event uses a function with your previously entered data as an argument (and the index as a second argument) so you don't need to use enter() a second time.

    vis.selectAll("circle")
    .data(datafiltered).enter().append("svg:circle")
    .attr("cx", function(d) { return x(d.x);})
    .attr("cy", function(d) {return y(d.y)})
    .attr("fill", "red").attr("r", 15)
    .on("mouseover", function(d,i) {
        d3.select(this).append("text")
            .text( d.x)
            .attr("x", x(d.x))
            .attr("y", y(d.y)); 
    });
    

提交回复
热议问题