Return to Snippet

Revision: 64793
at September 21, 2013 00:34 by uberdragon


Initial Code
function compute_rank_ticks(min, max){
    var start = min%2==1 ? min : min-1;
    var end = max%2==1 ? max : max+1;
    var span = end-start;
    var step = 1;
    var notches = Math.ceil(span/step);

    if(span == 0){
      if(min == 1){
        return [1, 2, 3];
      }
      else{
        return [min - 1, min, min + 1];
      }
    }

    while(notches > 10){
      step = step + 1;
      notches = Math.ceil(span/step);
    }

    var ticks = [];
    var tick = start;
    var i;
    for(i=0; i<=notches; i++){
      ticks.push(tick);
      tick = tick + step;
    }

    return ticks;
  }

Initial URL

                                

Initial Description
This will calculate the ticks for google charts so that you can have a chart with a defined height, and still represent large data ranges with out all the vertical information getting bunched up together.

Initial Title
Calculate ticks for gChart Y axis - accommodates large ranges

Initial Tags
google

Initial Language
JavaScript