/ Published in: JavaScript

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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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; }
Comments
