Google图表 - 避免在yAxis中显示负值

Hom*_*ith 17 javascript google-visualization

我有以下代码:

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'
           }
      );
}
Run Code Online (Sandbox Code Playgroud)

这给了我以下图表 图表

如何避免在yAxis中显示负值?我试过添加 vAxis: {minValue:0}没有任何运气.

这些图表有一个游乐场/沙箱:Google Charts Playground

小智 53

您需要将viewWindowMode设置为显式

vAxis: {viewWindowMode: "explicit", viewWindow:{ min: 0 }}
Run Code Online (Sandbox Code Playgroud)


bil*_*oah 5

viewWindowMode: "explicit"在当前版本中已弃用,它使用vAxis.viewWindow.min

vAxis: {
    viewWindow: {
        min: 0
    }
}
Run Code Online (Sandbox Code Playgroud)