2012-07-04 194 views
1

我創建了一些基於一些簡單閾值的結果的熱圖。我使用JavaScript來創建,設置值和背景顏色。預期的結果是使用一些blue不同色調的熱圖。但是,沒有被染色,並通過分析DOM,我發現:單元格背景顏色不變javascript

<td>1</td> 
<td>1</td> 
<td>1</td> 
<td>1</td> 
<td>1</td> 
<td>1</td> 

因此,bgcolor="#"沒有設置。我已經使用了bgcolorsetAtribute,但結果是一樣的:沒有任何顏色。我的功能如下:

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

任何想法? > BGCOLOR - 感謝

回答

2
cell.style.backgroundColor="red" 
+0

我改爲'cell [j] .style.backgroundColor =「red」;'但是我得到了同樣的結果:沒有東西被着色。 – cybertextron

+0

也使用內置的表函數即。 table.insertRow(-1)和row.insertCell(-1)...它的成本較低,然後創建和追加..並使較短的代碼 – dano

0

你在的bgcolor屬性需要一個大寫的溫度。