谷歌图表 - 避免在Y轴负值(Google Charts - Avoid showing negat

2019-07-29 18:43发布

我有以下代码:

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'
           }
      );
}

这给了我如下图

我该怎么做才能避免显示在Y轴负值? 我曾尝试加入vAxis: {minValue:0}没有任何的运气。

没有这些图表游乐场/沙箱: 谷歌图表游乐场

Answer 1:

您需要设置viewWindowMode为明确

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


Answer 2:

viewWindowMode: "explicit"不推荐在使用当前版本: vAxis.viewWindow.min

vAxis: {
    viewWindow: {
        min: 0
    }
}


文章来源: Google Charts - Avoid showing negative values in yAxis