在dc.js中对数据表进行颜色编码 [英] Color code a data table in dc.js

查看:78
本文介绍了在dc.js中对数据表进行颜色编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本的问题,对dc.js的了解很少。
我试图使用我拥有的数据创建一个记分卡,并使用dc.js将其显示为数据表。我正在通过交叉过滤器处理数据。

I have a vary basic question and very little understanding of dc.js. I am trying to create a score card using the data that i have and display it as a data table using dc.js.I am processing the data through crossfilter.

如何对数据表中的条目进行颜色编码。假设我的表格的值从-1到1,我要按如下所示对单元格进行着色:
-1到0:红色
的梯度递减0:白色
0到1:递增绿色渐变

How can i color code the entries in the data table. Say my table will have values from -1 to 1 and i want to color the cells as follows: -1 to 0 : decreasing gradient of red 0 : white 0 to 1 : increasing gradient of green

我知道我无法提供任何代码,但是那是因为我完全不知道如何实现这一目标。会非常感谢您的帮助。

I know i am not able to provide any code but thats because i am at a total loss on how to achieve this. Help will be really appreciated.

谢谢。

推荐答案

我正在使用datatables jquery插件。

I'm using datatables jquery plugin.

{ targets: 3, 
data: function (d) {
    if (d.Rating<5) {       return '<span class="red">'+d.Rating+'</span>' ;}
    else if (d.Rating<7) {  return '<span class="yellow">'+d.Rating+'</span>' ;}
    else if (d.Rating<=10) {return '<span class="green">'+d.Rating+'</span>' ;}
    else {                  return '<span class="grey">'+d.Rating+'</span>' ;}
}}

您可以根据需要创建任意类别。

然后使用CSS修改外观。

you can make as much categories as you want.
And modify appearence with css like this.

.red{ background-color:red; }
.yellow{ background-color:yellow; }
.green{ background-color:green; }

这篇关于在dc.js中对数据表进行颜色编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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