perl CGI (65)
Visual Basic (3539)
New related comments
Number of comments in the last 48 hours
Calculate the optimal maximum value for a y axis in a chart
This article has not been rated yet. After reading, feel free to leave comments and rate it.
Question:I am generating a chart graph, and need to programatically generate the axis labels. My vertical (y) data range is not fixed = not predictable.
Answer:Use the function below to round your biggest value up to the nearest number that divides by 100 or 25.
E.g. 145 would be rounded up to 150 and you would have 6 intervals with a step of 25. If your maximal number is 385678 then it would round up to 400000 and you would have a step of 100000.
Use it like this:
my ($display_max_data, $vertical_step) = roundup(int($max_data);
max_data is the biggest value, the returned display_max_data is greater or equal to it.