【问题标题】:Tooltip fetching incorrect data获取错误数据的工具提示
【发布时间】:2014-02-28 05:54:14
【问题描述】:

请参考这个小提琴:http://jsfiddle.net/rdesai/5stce/40/

工具提示获取的数据不正确。我该如何解决?

相关部分代码:

episode.selectAll("rect")
.data(function(d) { return d.ages; })
.enter().append("rect")
.attr("width", x.rangeBand() - 15)
.attr("y", function(d) { return y(d.y1); })
.attr("height", function(d) { return y(d.y0) - y(d.y1); })
.style("fill", function(d) { return color(d.name); })
.on("mouseover", function(d) {      
    tooltip.transition().duration(200).style("opacity", .9);      
    tooltip.html("YES: " + Number(d.y1*100) + "%<br/>NO: " + Number(d.y0*100) + "%")  
    .style("left", (d3.event.pageX) + "px")     
    .style("top", (d3.event.pageY - 28) + "px");    
})                  
.on("mouseout", function(d) {       
    tooltip.transition().duration(500).style("opacity", 0);   
});

【问题讨论】:

    标签: javascript json d3.js


    【解决方案1】:

    我尝试过,但无法使用您的代码。所以我用另一种方法来查找百分比,如果你喜欢的话。

    Fiddle

       var x=Number($(this).attr("height"))/45;
       if($(this).css("fill")=="rgb(255, 51, 50)"){
       tooltip.html("YES: " + Number((10-x)*10) + "%<br/>NO: " + Number(x*10) + "%")
        }
       else
       {
        tooltip.html("YES: " + Number((x)*10) + "%<br/>NO: " + Number(10-x)*10 + "%")
       }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-08
    • 1970-01-01
    • 2015-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-22
    • 2015-07-20
    相关资源
    最近更新 更多