Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Charts - Avoid showing negative values in yAxis

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

like image 691
Hommer Smith Avatar asked Jun 07 '12 18:06

Hommer Smith


People also ask

Is Google charts deprecated?

The Google Chart API is an interactive Web service (now deprecated) that creates graphical charts from user-supplied data.

How do I graph negative numbers?

Negative numbers are to the left of the origin on the x-axis and below the origin on the y-axis. To graph with negative numbers, start at the origin and go to the left if the x-value is negative, and downward if the y-coordinate is negative. Points in quadrant I will always follow the format (+, +).


1 Answers

You need to set viewWindowMode as explicit

vAxis: {viewWindowMode: "explicit", viewWindow:{ min: 0 }}
like image 98
OscarMedina Avatar answered Oct 12 '22 22:10

OscarMedina