2016-01-13 45 views
0

任何想法如何實現同一行上的x和y值?如何在最新的google圖表api中實現以下圖表?

目前,我已經達到這一點,並有相當大的問題,以設置其他兩個行1上的x和y。

var options = { 
    isStacked:true, 
    hAxis: { 
     gridlines: { 
      color: '#fff', 
      count: 8 
     }, 
     showTextEvery: 1, 
     title: 'КМ/Ч' 
    }, 
    vAxis: { 
     gridlines: { 
      color: '#fff', 
      count: 8 
     }, 
     minorGridlines: { 
      color: 'red' 
     }, 
     viewWindowMode: 'explicit', 
     viewWindow: { 
      max: 100 
     }, 
     title: 'ЧАС' 
    }, 
    axisTitlesPosition: 'out', 
    axes: { 
     y: { 
      0: { side: 'top'} 
     } 
    }, 
    legend: { 
     position: 'none' 
    }, 
    annotations: { 
    }, 
    backgroundColor: { 
     stroke: '#fff', 
     fill: '#fff', 
     strokeWidth: 0 
    } 
}; 

http://jsfiddle.net/Qquse/1645/

Example image

回答

0

如果我理解你的問題,你想從陣列中的每一行繪製兩個值。

問題是LineChart正在尋找某種類型的標籤在第一列用於h軸。

在這裏,我使用了一個視圖,爲行標籤創建重複列...

function drawChart() { 
 
    var data = new google.visualization.DataTable(); 
 
    data.addColumn('number', 'X'); 
 
    data.addColumn('number', 'Dogs'); 
 

 
    data.addRows([ 
 
     [1, 10], [2, 23], [3, 17], [4, 18], [5, 9], [11, 35], 
 
     [6, 11], [7, 27], [8, 33], [9, 40], [10, 32], [11, 35], 
 
     [12, 30], [13, 40], [14, 42], [15, 47], [16, 44], [17, 48], 
 
     [18, 52], [19, 54], [20, 42], [21, 55], [22, 56], [23, 57], 
 
     [24, 60], [25, 50], [26, 52], [27, 51], [28, 49], [29, 53], 
 
     [30, 55], [31, 60], [32, 61], [33, 59], [34, 62], [35, 65], 
 
     [36, 62], [37, 58], [38, 55], [39, 61], [40, 64], [41, 65], 
 
     [42, 63], [43, 66], [44, 67], [45, 69], [46, 69], [47, 70], 
 
     [48, 72], [49, 68], [50, 66], [51, 65], [52, 67], [53, 70], 
 
     [54, 71], [55, 72], [56, 73], [57, 75], [58, 70], [59, 68], 
 
     [60, 64], [61, 60], [62, 65], [63, 67], [64, 68], [65, 69], 
 
     [66, 70], [67, 72], [68, 75], [69, 80] 
 
    ]); 
 

 
    var view = new google.visualization.DataView(data); 
 
    view.setColumns([{calc: "stringify", sourceColumn: 0, type: "string"},0,1]); 
 
    var chart = new google.visualization.LineChart(document.getElementById('chart')); 
 
    chart.draw(view, {}); 
 
} 
 

 
google.load("visualization", "1", {packages:["corechart"]}); 
 
google.setOnLoadCallback(drawChart);
<script src="https://www.google.com/jsapi"></script> 
 
<div id="chart"></div>

+0

希望這可以幫助,讓我知道如果我錯過了什麼? – WhiteHat