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

3

13

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

Also answered 25/2, 2014 at 14:57 Comment(0)
A
24

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

            vAxis: {
                minValue:0,
                viewWindow: {
                    min: 0
                }
            }
Amaliaamalie answered 25/2, 2014 at 16:46 Comment(2)
Not working for me, might be obsolete unfortunatelySoma
This did not work for me either with all zero valuesLockout
C
5

This can be achieved by setting the viewwindow values.

    vAxis: { viewWindow: { min: 0 }, viewWindowMode: "explicit" }
Carpenter answered 30/9, 2016 at 7:14 Comment(0)
P
5

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'
  }
}
Possessed answered 3/12, 2019 at 8:36 Comment(1)
this is it for me, you need to set the max, not just the min, for anything to changeIdiocrasy

© 2022 - 2024 — McMap. All rights reserved.