DC图表中的条件着色 [英] Conditional coloring in dc charts
本文介绍了DC图表中的条件着色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用dc.js a创建一个饼图以显示损益,如何根据饼图的颜色变化来设置条件.
I am using dc.js a to create a pie chart to show gain and loss, How can I put some condition based on which the color of the pie chart changes.
我尝试使用
.colors(['#fdd752', '#AEC785', '#a48ad4', '#3acdc7'])
// (optional) define color domain to match your data domain if you want to bind data or color
.colorDomain([-1750, 1644])
// (optional) define color value accessor
.colorAccessor(function (d, i) {console.log(d); return d.value; })
有什么想法吗?
推荐答案
就像X轴刻度一样,色域可以是有序的,这意味着每个值都可以映射到调色板中的不同颜色,也可以是定量的,以实现连续颜色.
Just like X-axis scales, the color domain can be ordinal, which means each value maps to a different color out of a palette, or quantitative, for continuous colors.
默认情况下,饼图(和其他大多数饼图)使用序数标度,但是如果您要使用连续值进行着色,则线性标度可能是最好的.
By default the pie chart (and most of the others) uses an ordinal scale, but if you mean to color by a continuous value, a linear scale might be best.
例如
chart.linearColors(['red', 'green'])
.colorDomain([-1750, 1644])
.colorAccessor(function (d, i) {console.log(d); return d.value; })
这篇关于DC图表中的条件着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文