NVD3.js着色图中的特定条 [英] NVD3.js coloring specific bars in graph
本文介绍了NVD3.js着色图中的特定条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有办法为特定的酒吧着色吗?
Is there a way to color specific bars? If a bar is less than the line, color it red.
代码: https://github.com/tvinci/webs/blob/gh-pages/lineplusbar.html
示例: http://tvinci.github.io/webs/lineplusbar.html
我想这样做,但i的值不是我发送的y值。它已被修改:
I'd like to do something like this but the value for i is not the y value that I send in. It has been modified:
d3.selectAll("rect.nv-bar")
.style("fill", function(d, i){
return i > 50 ? "red":"blue";
});
资料:
var overview_data=[
{
"key" : "Achieved",
"bar": true,
"values" : [ [ "1x" , 30] , [ "2x" , 70] , [ "3x" , 200] ]
},
{
"key" : "Required",
"values" : [ [ "1x" , 50] , [ "2x" , 100] , [ "3x" , 150] ]
}
].map(function(series) {
series.values = series.values.map(function(d) { return {x: d[0], y: d[1] } });
return series;
});
推荐答案
您可以:
d3.selectAll("rect.nv-bar")
.style("fill", function(d, i){
return d.y > 50 ? "red":"blue";
});
这篇关于NVD3.js着色图中的特定条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文