Color code for data table in dc.js

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

How can I encode code in a data table . Say my table will have values ​​from -1 to 1, and I want to color the cells as follows: -1 to 0: decrease the red gradient 0: white 0 to 1: increase the green gradient

I know that I cannot provide any code, but that is because I am at a complete loss of how to achieve this. Help will be really appreciated.

Thank.

+2
source share
1

css.

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, .

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

All Articles