如何分配随机颜色到D3条形图? [英] How to assign random colors to D3 bar chart?

查看:228
本文介绍了如何分配随机颜色到D3条形图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按照以下模型制作D3条形图:





如何让酒吧有随机颜色?



jsFiddle



代码:

  svg.append(g)
.attr(class,x axis)
.attr(transform,translate(0,+ height +))
.call(xAxis);


解决方案

d3有4个内置调色板。 >

以下是 <$



/www.dashingd3js.com/d3js-scalesrel =noreferrer> 教程适合使用特定颜色



另一个

>官方
网站 for d3 colors。



Fiddle - 注意:在小提琴中,我通过在数据中添加颜色来传递颜色。



它甚至可以通过传递不同变量的颜色来完成。



希望这有助于。


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

How do I make the bars to have random colors?

jsFiddle

Code:

svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);

解决方案

d3 has 4 built in color palettes.

Here's the link for the built in color palettes.

This tutorial is good on using specific colors for specific element.

Another tutorial by Jerome Cukier.

And the official site for d3 colors.

Fiddle - Note: In the fiddle I've passed the colors by adding colors in the data.

It can even be done by passing the colors from a different variables.

Hope this helps.

这篇关于如何分配随机颜色到D3条形图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆