2016-01-20 90 views
1

如何更改谷歌圖表中列的顏色。我有這個drawGraph功能:更改谷歌圖表中列的顏色

function drawGraph(){ 
    var data = new google.visualization.DataTable(); 
    data.addColumn('date', 'Date'); 
    data.addColumn('number', 'House 1') 
    data.addColumn('number', 'House 2') 
    data.addColumn('number', 'House 3') 
    data.addColumn('number', 'House 4') 

    data.addRows([ 
    [new Date(2016, 01, 20), 
     180, 
     150, 
     186, 
     176, 
    ], 
    [new Date(2016, 01, 19), 
     100, 
     150, 
     200, 
     175, 
    ], 
    [new Date(2016, 01, 11), 
     10, 
     11, 
     20, 
     17, 
    ], 
    [new Date(2016, 01, 07), 
     55, 
     51, 
     123, 
     100, 
    ], 
    ]) 

    var options = { 
    title: 'House Points', 
    hAxis: { 
     title: 'Date' 
    }, 
    vAxis: { 
     title: 'Points' 
    } 
    } 

    var material = new google.charts.Bar(document.getElementById('edhp_housepoints')); 
    material.draw(data, options); 
} 

我想設置顏色樓1至4我該怎麼做?

我嘗試了一些東西,但沒有一個能夠正常工作。

回答

0

顏色爲每列可以在選項中設置散列像這樣:

var options = { 
    title: 'House Points', 
    hAxis: { 
    title: 'Date' 
    }, 
    vAxis: { 
    title: 'Points' 
    }, 
    colors: [ 
    "#f0c514", 
    "#eb7f25", 
    "#eb4b33", 
    "#22b05a" 
    ] 
} 
+1

你還可以在'系列中指定的顏色:{0:{顏色:「黑」}}' – WhiteHat