简体   繁体   English

更改dc.js图表​​颜色

[英]Change dc.js chart colours

Why are all dc.js charts blue in colour? 为什么所有dc.js图表​​都是蓝色的? And how do I change it? 我该如何改变呢? Went through the dc.css, didn't see much use of the blue colour there! 经过dc.css,没有看到太多蓝色的使用!

I tried changing the fill property of quite a few. 我尝试改变了很多fill属性。 The only ones I got successful for were the bar charts. 我唯一成功的是条形图。 Still no clue for the pie charts. 仍然没有饼图的线索。

Colors in dc.js (and quite often in d3 in general) are dynamically calculated based on the data, which is why you won't usually find them in the CSS. dc.js中的颜色(通常是d3中的颜色)是根据数据动态计算的,这就是您通常不会在CSS中找到它们的原因。 This takes some getting used to. 这需要一些人习惯。

In the case of bar charts, the colors are based on the stack number. 在条形图的情况下,颜色基于堆栈编号。 In pie charts, they are based on the pie slice. 在饼图中,它们基于饼图切片。

Then they go through a d3 scale in order to assign the actual colors. 然后他们通过d3比例来分配实际颜色。 Typically you want to use chart.ordinalColors to replace the color scale with one with your own colors. 通常,您希望使用chart.ordinalColors将颜色标度替换为具有您自己颜色的颜色标度。

So, eg using one of the colorbrewer palettes: 因此,例如使用其中一个colorbrewer调色板:

chart.ordinalColors(['#e41a1c','#377eb8','#4daf4a','#984ea3','#ff7f00','#ffff33','#a65628']);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM