2013-07-12 61 views
0

是否可以使THIS圖表中的條形堆積在THIS圖表中?Stacked Google可視化圖表

請讓我知道這是可能的,以及如何做到這一點。 我必須堅持使用Google可視化圖表。

您也可以拋出下面的代碼在HERE

疊式圖:

function drawVisualization() { 
    // Create and populate the data table. 
    var data = new google.visualization.DataTable(); 
    data.addColumn('string', 'Year'); 
    data.addColumn('number', 'Sales'); 
    data.addColumn({type: 'string', role: 'tooltip'}); 
    data.addColumn('number', 'Expenses'); 
    data.addColumn({type: 'string', role: 'tooltip'}); 
    data.addRows([ 
    ['2004', 1000, '1M$ sales in 2004', 400, '$0.4M expenses in 2004'], 
    ['2005', 1170, '1.17M$ sales in 2005', 460, '$0.46M expenses in 2005'], 
    ['2006', 660, '.66$ sales in 2006', 1120, '$1.12M expenses in 2006'], 
    ['2007', 1030, '1.03M$ sales in 2007', 540, '$0.54M expenses in 2007'] 
    ]); 

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

其他圖:

function drawVisualization() { 
    // Create and populate the data table. 
    var data = google.visualization.arrayToDataTable([ 
    ['Year', 'Austria', 'Belgium', 'Czech Republic', 'Finland', 'France', 'Germany'], 
    ['2003', 1336060, 3817614,  974066,  1104797, 6651824, 15727003], 
    ['2004', 1538156, 3968305,  928875,  1151983, 5940129, 17356071], 
    ['2005', 1576579, 4063225,  1063414,  1156441, 5714009, 16716049], 
    ['2006', 1600652, 4604684,  940478,  1167979, 6190532, 18542843], 
    ['2007', 1968113, 4013653,  1037079,  1207029, 6420270, 19564053], 
    ['2008', 1901067, 6792087,  1037327,  1284795, 6240921, 19830493] 
    ]); 

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

我發現這不是由谷歌可視化API目前支持。有一個解決方法,可以找到[這裏](http://jsfiddle.net/asgallant/7yHz7/),但它是很多工作,而不是有用的。順便說一句,這是一種破解。謝謝。 – MmynameStackflow

回答

0

如果谷歌的可視化是對你的項目我的要求不知道如何做到這一點,但dimple使這種事情很容易,請參閱示例here

+0

你說得對。鏈接現在可以正常工作。是的,我僅限於谷歌可視化圖表。 – MmynameStackflow

0

是的,可以根據需要製作條形。在你的選擇,你需要添加此語句 isStacked:true 這裏是工作sample.更多谷歌圖表相關查詢看看jqfaq.com

+0

這不像我提到的。就像在第一個例子中,數據已經被細分。我不想改變外觀,但我希望第一個示例中的酒吧可以按照他們現在顯示的方式進行堆疊。 – MmynameStackflow