2012-05-04 80 views

回答

28

的谷歌開發者網站上提供了有關條形圖格式的一些細節:https://developers.google.com/chart/interactive/docs/gallery/barchart

要進行正常的條形圖堆積,需要用戶isStacked: true選項。您可以複製並粘貼以下代碼到圖表工具操場上看到一個工作示例: http://code.google.com/apis/ajax/playground/?type=visualization

function drawVisualization() { 
    // Create and populate the data table. 
    var data = google.visualization.arrayToDataTable([ 
    ['Year', 'Austria', 'Bulgaria', 'Denmark', 'Greece'], 
    ['2003', 1336060, 400361, 1001582, 997974], 
    ['2004', 1538156, 366849, 1119450, 941795], 
    ['2005', 1576579, 440514, 993360, 930593], 
    ['2006', 1600652, 434552, 1004163, 897127], 
    ['2007', 1968113, 393032, 979198, 1080887], 
    ['2008', 1901067, 517206, 916965, 1056036] 
    ]); 

    // Create and draw the visualization. 
    new google.visualization.BarChart(document.getElementById('visualization')). 
     draw(data, 
      {title:"Yearly Coffee Consumption by Country", 
      width:600, height:400, 
      vAxis: {title: "Year"}, 
      hAxis: {title: "Cups"}, 
      isStacked: true} 
    ); 
} 

您可能也有興趣在一個堆積面積圖,這取決於您要顯示的數據。

還有一個問題,這給使用圖表工具圖像API堆積條形圖的例子:Bar chart in Javascript: stacked bars + grouped bars

需要注意的是谷歌圖表工具的圖片圖表部分,2012年4月20日,正式棄用。根據Google的棄用政策,圖片圖表仍然可以使用一段時間,但我建議您專注於上述交互式HTML5 + SVG實施。

+0

謝謝,丹尼爾。 –