0
给定一个包含2个数据集的条形图。我怎样才能给每个酒吧自己的颜色?VueJS动态条形图颜色
svg.selectAll(".bar")
.data(data)
.enter().append("rect")
.style("fill", function(d,i) { console.log(i.fill) } // <- first red, second blue
给定一个包含2个数据集的条形图。我怎样才能给每个酒吧自己的颜色?VueJS动态条形图颜色
svg.selectAll(".bar")
.data(data)
.enter().append("rect")
.style("fill", function(d,i) { console.log(i.fill) } // <- first red, second blue
我懒得设立了什么,我认为可能的工作演示,但我想你想要的颜色,如数组:
var colors = ['red', 'blue'];
然后在回调fill
可以这样做:
return colors[i % colors.length];
如果我的假设正确i
是你在bar
的索引。