Reputation: 10961
I'm creating a heatmap for some results I have based on some simple thresholds. I'm using JavaScript to create, set up the value and the background color. The expected result is a heatmap using some blue
different tonalities. However, nothing is being colored, and by analysing the DOM I found:
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
Thus, the bgcolor="#"
is not setup. I have used both bgcolor
and setAtribute
, but the result it is the same: nothing is being colored. My function is posted below:
function makeTable(data)
{
var row = new Array();
var cell = new Array();
var row_num = 26;
var cell_num = 44;
var tab = document.createElement('table');
tab.setAttribute('id', 'newtable');
tab.border = '1px';
var tbo = document.createElement('tbody');
for(var i = 0; i < row_num; i++){
row[i] = document.createElement('tr');
var upper = (i+1)*44;
var lower = i*44;
for(var j = lower; j < upper; j++){
cell[j] = document.createElement('td');
if(data[j] != undefined){
var index = document.createTextNode(data[j].diff);
cell[j].appendChild(index);
/* specify which color better suits the heatmap */
if(index >= 0 || index <= 100){
cell[j].bgcolor = "#ADDDE6";
}
else if(index > 100 || index <= 1000){
cell[j].bgcolor = "#00BFFF";
}
else if(index > 1000 || index <= 4000){
cell[j].bgcolor = "#6495ED";
}
else if(index > 4000 || index <= 6000){
cell[j].bgcolor = "#00008B";
}
else{
cell[j].bgcolor = "#0000FF";
}
row[i].appendChild(cell[j]);
}
}
tbo.appendChild(row[i]);
}
tab.appendChild(tbo);
document.getElementById('mytable').appendChild(tab);
}
Any ideas? Thanks
Upvotes: 1
Views: 1060