Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 408
Peter Parker Avatar asked Feb 25 '14 14:02

Peter Parker


People also ask

How do you show no data available on Google chart?

Use noData() method to enable "No data" label: chart. noData().

How do I change the color of my Google bar graph?

To change the colors assigned to data series in a specific chart: Select that chart, then on the right, open the STYLE tab. In the Color by section, select Series order, Bar order, or Slice order, depending on the type of chart. Click a color box to set the color for each series.


3 Answers

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'
  }
}
like image 85
Юрий Ярвинен Avatar answered Sep 25 '22 06:09

Юрий Ярвинен


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

            vAxis: {
                minValue:0,
                viewWindow: {
                    min: 0
                }
            }
like image 23
Anto Jurković Avatar answered Oct 18 '22 15:10

Anto Jurković


This can be achieved by setting the viewwindow values.

    vAxis: { viewWindow: { min: 0 }, viewWindowMode: "explicit" }
like image 5
jothi Avatar answered Oct 18 '22 14:10

jothi