jquery tipsy tooltip not working with d3.js circles

99封情书 提交于 2020-01-05 05:49:07

问题


Here is my d3.js code

var circles = vis.selectAll("circle").data(data)
circles
    .enter()
        .append("svg:circle")
            .attr("stroke", "black")
            .attr("cx", function (d) { return xRange(d.year); })
            .attr("cy", function (d) { return yRange(d.count); })
            .style("fill", function(d,i){return color(i);})
        .append("svg:title")
            .text(function (d) { return d.corpus; })

In the end i have appended a tooltip to the circles.I tried to attach jquery tipsy tooltip to the circles but did'nt work.Here is how i did it(i followed http://bl.ocks.org/1373263)

var circles = vis.selectAll("circle").data(data)
circles
    .enter()
        .append("svg:circle")
            .attr("stroke", "black")
            .attr("cx", function (d) { return xRange(d.year); })
            .attr("cy", function (d) { return yRange(d.count); })
            .style("fill", function(d,i){return color(i);})
        $('svg circle').tipsy({ 
                            gravity: 'w', 
                            html: true, 
                            title: function (d) {
                            return d.corpus;
                          }
                       });

But its not working.


回答1:


You are missing this.data

$('svg circle').tipsy({ 
                            gravity: 'w', 
                            html: true, 
                            title: function (d) {
                               var d = this.__data__;
                               return d.corpus;
                          }
                       });


来源:https://stackoverflow.com/questions/13568802/jquery-tipsy-tooltip-not-working-with-d3-js-circles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!