2017-09-05 218 views
0

我想根据我在控制器中选择的一些标准,从时间线上颜色的一些酒吧,我想要的颜色。我在页面呈现谷歌图表的时间轴不识别颜色

{ 
    "cols": [ 
    { "id": "", "label": "Project Name", "pattern": "", "role": "", "type": "string" }, 
    { "id": "", "label": "Period", "pattern": "", "role": "", "type": "string" }, 
    { "id": "", "label": "Start", "pattern": "", "role": "", "type": "date" }, 
    { "id": "", "label": "End", "pattern": "", "role": "", "type": "date" }, 
    { "id": "", "label": "", "pattern": "", "role": "style", "type": "string"}], 
    "rows": [ 
    { "c": [{ "v": "test", "f": null},{"v": "Fesability", "f": null},{"v": 1504224000000,"f": null},{"v": 1504742400000,"f": null},{"v": "#45a128","f": null}]}, 
    { "c": [{ "v": "test", "f": null},{"v": "Conceptual", "f": null},{"v": 1504742400000,"f": null},{"v": 1505347200000,"f": null},{"v": "#45a128","f": null}]}] 
} 

和脚本:一个用作数据是下一个JSON的

<script> 
    google.charts.load('current', { 'packages': ['timeline'] }); 
    google.charts.setOnLoadCallback(drawChart); 

    function drawChart() { 
     var jsonData = $.ajax({ 
      url: '/Report/[email protected]', 
      dataType: "json", 
      async: false 
     }).responseText; 


     // Create our data table out of JSON data loaded from server. 
     var data = new google.visualization.DataTable(jsonData); 

     // Instantiate and draw our chart, passing in some options. 
     var chart = new google.visualization.Timeline(document.getElementById('timeline')); 

     chart.draw(data); 
    } 
</script> 

的问题是,我想它不上色吧。我也尝试过'颜色:#435278',结果相同,不工作。

回答

0

订单对于列来说很重要,所以Google Charts只有在它是第三个时才会识别样式列。我将json格式化为这个,并且一切正常。新的JSON看起来是这样的:

{ 
    "cols": [ 
    { "id": "", "label": "Project Name", "pattern": "", "role": "", "type": "string" }, 
    { "id": "", "label": "Period", "pattern": "", "role": "", "type": "string" }, 
    { "id": "", "label": "", "pattern": "", "role": "style", "type": "string"} 
    { "id": "", "label": "Start", "pattern": "", "role": "", "type": "date" }, 
    { "id": "", "label": "End", "pattern": "", "role": "", "type": "date" }], 
    "rows": [ 
    { "c": [{ "v": "test", "f": null},{"v": "Fesability", "f": null},{"v": "#45a128","f": null},{"v": 1504224000000,"f": null},{"v": 1504742400000,"f": null}]}, 
    { "c": [{ "v": "test", "f": null},{"v": "Conceptual", "f": null},{"v": "#45a128","f": null},{"v": 1504742400000,"f": null},{"v": 1505347200000,"f": null}]}] 

}