NVD3.js在图中着色特定条

use*_*754 2 svg d3.js nvd3.js

有没有办法给特定的酒吧着色?如果条形小于线条,则将其着色为红色.

代码:https://github.com/tvinci/webs/blob/gh-pages/lineplusbar.html

示例:http://tvinci.github.io/webs/lineplusbar.html

我想做这样的事情,但i的值不是我发送的y值.它已被修改:

d3.selectAll("rect.nv-bar")
    .style("fill", function(d, i){
        return i > 50 ? "red":"blue";
    });
Run Code Online (Sandbox Code Playgroud)

数据:

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;
});
Run Code Online (Sandbox Code Playgroud)

Cih*_*ser 5

你可以做:

d3.selectAll("rect.nv-bar")
    .style("fill", function(d, i){
        return d.y > 50 ? "red":"blue";
    });
Run Code Online (Sandbox Code Playgroud)