2016-09-26 71 views
0

给定一个包含2个数据集的条形图。我怎样才能给每个酒吧自己的颜色?VueJS动态条形图颜色

svg.selectAll(".bar") 
    .data(data) 
    .enter().append("rect") 
    .style("fill", function(d,i) { console.log(i.fill) } // <- first red, second blue 

回答

1

我懒得设立了什么,我认为可能的工作演示,但我想你想要的颜色,如数组:

var colors = ['red', 'blue']; 

然后在回调fill可以这样做:

return colors[i % colors.length]; 

如果我的假设正确i是你在bar的索引。