3

特定のバーに色を付ける方法はありますか? 棒が線よりも小さい場合は、赤にします。

コード: 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";
    });

データ:

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

2 に答える 2

5

できるよ:

d3.selectAll("rect.nv-bar")
    .style("fill", function(d, i){
        return d.y > 50 ? "red":"blue";
    });
于 2013-04-11T12:13:43.137 に答える