我正在根据下面的模型制作D3条形图:

如何使条纹具有随机颜色?
码:
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
Run Code Online (Sandbox Code Playgroud)
colors = d3.scale.category20()
rects = svg.selectAll('rect')
.data(data)
.enter()
.append("rect")
.attr("class","rect")
.....#other attributes
.attr("fill",function(d,i){return colors(i)})
Run Code Online (Sandbox Code Playgroud)