2013-01-02 19 views
1

的我有,我想與ColumnCharts渲染直方圖,我也跟着教程,並做到了,得到這個作爲一個結果:谷歌圖表工具破除水平間距

enter image description here

注意的間距在圖表的任一端(特別是左側的右側有一些非常小的列)

我試圖使用viewWindow,但它似乎沒有特別的效果。這是用來繪製它的代碼(coffeescript)。數據已被剪切以節省空間,因爲它們相當大

data = google.visualization.arrayToDataTable([ 
     labels, bardata 
    ]) 

    # The labels are ["x", "label for each column" ....] 
    # bardata is [number, number, number] (these numbers are the height of the column) 


    chart = new google.visualization.ColumnChart(document.getElementById("enrollment-total-chart")) 
    chart.draw(data, 
     width: 400 
     height: 300 
     hAxis: 
     title: "Number of students" 
     vAxis: 
     title: "Number of schools" 
     viewWindow: 
     max: "auto" 
     min: 0 
     viewWindowMode: "explicit" 
     legend: position: "none" 
    ) 

回答

0

這個問題可能與您的數據有關。舉例來說,如果我有這樣的圖表:

function drawVisualization() { 
    // Create and populate the data table. 
    var data = google.visualization.arrayToDataTable([ 
    ['x', 'A', 'B', 'C', 'D', 'E', 'F'], 
    ['A', 0, 0, 3, 4, 5, 0], 
    ]); 

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

有很多的在圖表的左/右空白由於零(我的猜測是,你必須在極端很多零的) 。

我對你的數據有點困惑 - 你說你有很多不同的行,但直方圖只是一對XY數據,所以顏色的使用(區分系列)有點不同於一個標準直方圖。

如果上述方法不回答你的問題,請您提供您的數據,讓我們可以瞭解一個好一點你想要做什麼(如果需要匿名)。

+1

的數據是相當大的,但你說得對:這是由於在右端非常小的數據。不知道我切換顯示時左端如何。我還通過使用列而不是行來濫用Google DataTable。 – Pwnna

+0

你的軸是否連續?如果沒有,那麼你不能設置ViewWindow(或者可以設置它,但它不會做任何事情)。如果你正在使用一個連續的軸,並且它不工作,那麼我不知道爲什麼。 – jmac