in reply to Dynamically Charting with Variable Dates and Data

I didn't like GD::Graph's algorithm to determine the maximal value, so I invented my own:
use POSIX qw(log10); my $round_to = 10 ** int(log10 $max) / 5; $max = $round_to * (1 + int($max / $round_to)); $p->set(y_max_value => $max );

In this case $max is the maximum value that appears in the data set. $round_to is first set to the next lower power of ten (so for example 35 is set to 10) and then divided by 5 (so that would be 2 here).

Then the maximum value is set to the next higher step of $round_to.

You can simply use $round_to, or a multiple thereof, as step value, or be inspired by my usage of logarithm+exponentiation+rounding to find your own formula.

Replies are listed 'Best First'.
Re^2: Dynamically Charting with Variable Dates and Data
by Anonymous Monk on Jan 12, 2009 at 22:57 UTC
    I like the numbers your algorithm is giving me. I'm going to use it. Thanks.