2012-06-07 113 views
15

負值我有以下代碼:谷歌圖表 - 避免在Y軸

function drawVisualization() { 
    // Create and populate the data table. 
    var data = google.visualization.arrayToDataTable([ 
    ['Year', 'People'], 
    ['2010',0] 
    ]); 

    // 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"}, 
      backgroundColor: 'none' 
      } 
    ); 
} 

這給了我下面的圖表chart

我該怎麼做才能避免顯示在Y軸負值?我已經嘗試加入 vAxis: {minValue:0}沒有任何運氣。

沒有爲這些圖表的遊樂場/沙箱:Google Charts Playground

回答

51

您需要設置viewWindowMode爲明確

vAxis: {viewWindowMode: "explicit", viewWindow:{ min: 0 }} 
+0

現在這個關於o它的手似乎解決了我的問題。謝謝! – slarti42uk

+4

這是正確的答案 –

+0

'viewWindowMode:「explicit」'不再需要,因爲它現在已經被棄用了。 https://developers.google.com/chart/interactive/docs/gallery/linechart#configuration-options – etoxin

3

viewWindowMode: "explicit"在目前的版本已經過時,它使用:vaxis.viewWindow.min

vAxis: { 
    viewWindow: { 
     min: 0 
    } 
} 
+0

正確地說,'viewWindowMode:「explicit」'已棄用。 [Soure](https://developers.google.com/chart/interactive/docs/gallery/linechart#configuration-options) – mshakeel