2014-09-02 36 views
2

我有許多行的時間表,每行都有幾張時間表。Google時間軸爲每個時間表修復不同的顏色

我想爲每個時間表修正一個確切的顏色,所以一種時間表在每一行中都會有相同的顏色。

我使用這個代碼:

var options = { 
     colors: ['#0C14F2', '#114C9E', '#ee8800', '#F6FF00'], 
     timeline: { 
      showBarLabels: false, 
      avoidOverlappingGridLines: false 
     }, 
     backgroundColor: '#f8f8ff'  
    }; 

這段代碼改變了顏色相宜隨機時間表的。

UPDATE:樣品JSON輸出

{"cols":[{"label":"Name","type":"string"},{"label":"Description","type":"string"},{"label":"Start","type":"date"},{"label":"End","type":"date"},{"role":"style","type":"string"}],"rows": 
[{"c":[{"v":"Sample Name"},{"v":"Sample Desc"},{"v":"Date(2014,09,09,0,0,0)"},{"v":"Date(2014,09,09,1,0,0)"},{"v":"#124T‌​9E"}]}, 

回答

2

使用「顏色」選項是不是最好的方法,因爲正確設置這個選項得到你想要的顏色的過程是相當複雜的。一個更簡單的方式做到這一點是使用「風格」的角色列有酒吧直接在它列出所需的顏色,例如:

var data = google.visualization.arrayToDataTable([ 
    ['Category', 'Name', {role: 'style'}, 'Start', 'End'], 
    ['Foo', 'Cad', '#a23c7a', new Date(2014, 7, 1), new Date(2014, 7, 5)], 
    ['Foo', 'Qud', '#40a67d', new Date(2014, 7, 3), new Date(2014, 7, 4)], 
    ['Bar', 'Fiz', '#5581b4', new Date(2014, 7, 2), new Date(2014, 7, 9)] 
]); 

見例如:http://jsfiddle.net/asgallant/qgo310pc/1/

[編輯在迴應評論]

您可以創建這樣在PHP中柱:

$table = array(
    'cols' => array(
     array('label' => 'Name', 'type' => 'string'), 
     array('label' => 'Description', 'type' => 'string'), 
     array('role' => 'style', 'type' => 'string'), 
     array('label' => 'Start', 'type' => 'date'), 
     array('label' => 'End', 'type' => 'date') 
    ) 
); 
+0

這似乎很大,但我怎麼能在P實現它惠普陣列?像這樣: http://paste.ubuntu.com/8256849/ – plaidshirt 2014-09-05 06:16:02

+0

感謝您的更新! – plaidshirt 2014-09-06 20:23:43

+0

我可以將顏色代碼存儲在簡單變量中嗎? $ color ='#ef8602'; – plaidshirt 2014-09-08 05:57:34