google-visualizationannotatedtimeline

Google Annotated Time Line chart (y-axis) scale


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.


Solution

  • 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.