0

I am using Google Annotated Time Line chart, I want the scale in the Y-axis to show integer numbers only, not fractions(if min is 0 and max is between 1,4).

I have tried to do it using max and min but there are cases where a line exceeds the max, so is there any method to force this chart to display only integer numbers. I have read the options in documentation many times but still no luck.

Tim
  • 4,217
  • 1
  • 15
  • 21
JokerDev
  • 151
  • 2
  • 15
  • Possible duplicate of [this question](http://stackoverflow.com/questions/14440231/google-charts-vertical-axis-in-whole-numbers/14472345#14472345). – jmac Oct 30 '13 at 05:36
  • 1
    but this vAxis: {maxValue: 10, format: '0'}} which is included in the answer is not valid in annotated time line chart,i have already tried to use it but seems to have no effect. but thanks anyway for your answer. – JokerDev Oct 30 '13 at 08:21
  • you're right -- I didn't realize it was annotated timeline. – jmac Oct 30 '13 at 23:46

1 Answers1

1

You can calculate the max of your data, and set the max of the chart based on that value, or 5, whichever is higher:

var max = 5;
for (var i = 1; i < data.getNumberOfColumns(); i++) {
    if (data.getColumnType(i) == 'number') {
        var range = data.getColumnRange(i);
        max = Math.max(max, range.max);
    }
}

Then in the chart's options, set max: max.

asgallant
  • 26,060
  • 6
  • 72
  • 87
  • This will have very odd behavior with negative numbers which may not work properly. It is much better to calculate both min and max in a function as explained in [this answer](http://stackoverflow.com/questions/14440231/google-charts-vertical-axis-in-whole-numbers/14472345#14472345) – jmac Oct 30 '13 at 05:37
  • The OP specified that the min was 0, so this is safe in this instance. I agree that calculating both is generally a better idea. – asgallant Oct 30 '13 at 10:10
  • thanks alot this worked for me ,but how you know the function getNumberOfColumns ,i cannot find it in the documentaion.?? – JokerDev Oct 30 '13 at 11:40
  • It is referenced in the DataTable documentation: https://developers.google.com/chart/interactive/docs/reference#DataTable_getNumberOfColumns – asgallant Oct 30 '13 at 15:13
  • i mean in annotated time line documentation,how it a function for datatable and worked in annotated time line?thanks anyway you are awesome!!! – JokerDev Oct 30 '13 at 15:53
  • I'm sorry, I don't understand your question. Could you clarify it? – asgallant Oct 30 '13 at 16:55
  • Sorry @asgallant, you're spot on there. – jmac Oct 30 '13 at 23:46