How to assign random colors to D3 bar chart?

后端 未结 3 555
花落未央
花落未央 2021-02-05 10:31

I am working on a D3 bar chart as per the mock-up below:

\"Bar

How do I make the bars to have rando

3条回答
  •  鱼传尺愫
    2021-02-05 11:00

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

提交回复
热议问题