Google Charts - Avoid showing negative values in yAxis

Hommer Smith picture Hommer Smith · Jun 7, 2012 · Viewed 11.5k times · Source

I have the following code:

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

Which gives me the following chart chart

How can I do to avoid showing negative values in the yAxis? I have tried adding vAxis: {minValue:0} without any luck.

There is a playground/sandbox for these charts: Google Charts Playground

Answer

OscarMedina picture OscarMedina · Jun 22, 2012

You need to set viewWindowMode as explicit

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