Conditional coloring in dc charts

泄露秘密 提交于 2020-01-16 18:53:08

问题


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.

I have tried using

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

Any ideas?


回答1:


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.

E.g.

chart.linearColors(['red', 'green'])
   .colorDomain([-1750, 1644])
   .colorAccessor(function (d, i) {console.log(d);  return d.value; })


来源:https://stackoverflow.com/questions/26178916/conditional-coloring-in-dc-charts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!