Peter Parker
Peter Parker

Reputation: 388

Google column chart vAxis.minValue doesn't work with all zero values

I am running into a case where all the data is by default coming as zero. Something like this:

    function drawVisualization() {
  // Create and populate the data table.
  var data = google.visualization.arrayToDataTable([
    ['Year', 'Austria', 'Belgium', 'Czech Republic', 'Finland', 'France', 'Germany'],
    ['2003',  0,   0,       0,       0,   0,  0],
    ['2004',  0,   0,       0,       0,   0,  0],
    ['2005',  0,   0,       0,      0,   0,  0],
    ['2006',  0,   0,       0,       0,   0,  0],
    ['2007',  0,   0,       0,       0,   0,  0],
    ['2008',  0,   0,       0,       0,   0,  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"},vAxis:{minValue:0,format:"#"}}
      );
}

If you copy above code and play around on google playground you will find that the graph is hard limiting the minimum value to -1.0. What I wanted is to start the vAxis from zero and pick only integral values. But it is not happening. I have also tried viewWindowMode but, it also couldn't solve the problem. Screenshot below of how it got rendered.enter image description here

Upvotes: 14

Views: 15487

Answers (3)

You nee to add max value in viewWindow and remove baseline by color it.

vAxis: {
  viewWindowMode: "explicit",   
  viewWindow: {min: 0,max:1}, 
  baseline:{
    color: '#F6F6F6'
  }
}

Upvotes: 5

jothi
jothi

Reputation: 362

This can be achieved by setting the viewwindow values.

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

Upvotes: 5

Anto Jurković
Anto Jurković

Reputation: 11258

You can fix it using viewWindow.min option (The minimum horizontal data value to render.), like:

            vAxis: {
                minValue:0,
                viewWindow: {
                    min: 0
                }
            }

Upvotes: 24

Related Questions