20
votes

chart

I have this Column Chart using Google's Visualization Chart API tools. How would I make it so the y-axis numbers are only positive whole numbers? I've tried looking through the documentation but can't seem to find anything.

8
I'm having the same problem...did you get an answer to this? - thegunner
All the below answers are incorrect. This isn't supported atm, and the workaround is to manipulate the min and max values so that the increment length happens to become 1 (I know that's not what you wanted to hear). Link - keyser

8 Answers

16
votes

I used the following and have not seen fractions since...

vAxis:{minValue:0,maxValue:5,gridlines:{count:6}}

The trick seems to be that with 6 gridlines and 5 as lowest 'high' value, the halves and tenths aren't applicable anymore.

12
votes

This worked for me

vAxis: {minValue:0, format:'#'}
6
votes

Simply use hAxis.format

example :

hAxis: {minValue:0,format:'0'},

format 0 = Digit

1
votes

Positive numbers:

You can use vAxis.minValue to set the lowest y-axis gridline, however the actual value of the gridline will be the minimum of what you set and the lowest value in your data, so if you have 0 in your data (as it seems you do for Unsatisfactory), this value will be used for the lowest y-axis gridline.

Whole numbers:

http://groups.google.com/group/google-visualization-api/browse_thread/thread/04a001766367dc0f/84c34338c2808069 - this is an older post, but as there is nothing in the chart API documentation, it seems the functionality to specify whole numbers only is still lacking.

Because the chart defaults to 5 gridlines (this is what you'd like to be able to override), if your highest data value is 2.0 (like in the example) you could force whole numbers by setting vAxis: {maxValue: 5}, although this may not be the most elegant solution.

0
votes

you can use the axisLabels feature. To use it, you must manually edit your axixLabels as shown here: http://code.google.com/apis/chart/image/docs/chart_params.html#axis_labels

e.g.:

chxt=x,y
chxp=0:|Excellent|Very Good|Fair|Unsatisfactory|1:|0|1|2

Greetings,

Jan

0
votes

If you change your graph type as follow:

google.load('visualization', '1', {'packages':['linechart']});

will work for you..

0
votes
var max=Math.max(1,10,15,20);(u have to pass the values what the values u have)
var maxvalue= max / 4;
var res=Math.floor(maxvalue);
res=res+1;
var remin= max % 4;
if(res != 0) {
    maxvalue=(res * 4);
}
else
    maxvalue= 4;

use the above code its working fine for me.

0
votes

The only workaround that I could find to this problem is that... For example, the default grid divisions are 4. You could change that number. But incase of the default (4) the vAxis.maxValue should be divisible by 4, if now increment that number so that it is.