工具提示获取不正确的数据 [英] Tooltip fetching incorrect data

查看:79
本文介绍了工具提示获取不正确的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参阅此小提琴: http://jsfiddle.net/rdesai/5stce/40/

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

The data that the tooltip is fetching is incorrect. How do I fix it?

代码的相关部分:

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);   
});

推荐答案

我尝试过,但无法在您的代码中使用.所以我想用另一种方法来找到百分比.

I tried but can't make it with your code. so i used another way to Find Percentages if you like use it.

小提琴

   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 + "%")
   }

这篇关于工具提示获取不正确的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆