Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To clarify: are you declaring the <code>y_max_value</code> height and your data is overflowing that bound? Or is GD::Graph miscalculating the correct upper limit?</p> <p>If you're setting the value, you need to fix your values to that upper bound. GD::Graph is only doing what you're telling it to do. (Which is more or less what Brian said).</p> <p>OTOH, I've found that GD::Graph doesn't always cope well with cumulative (stacked) graphs, and tends to overestimate the <code>y_max_value</code> in those circumstances. It can also produce some unattractive values on the Y axis, with floating point numbers at the tick values. Is this what you're really trying to solve?</p> <p>Having had both these problems, we've found a solution using Tie::RangeHash to create 'tidy' increments that always produce 5 integer tick points.</p> <pre><code>use Tie::RangeHash ; my $y_ranges = new Tie::RangeHash Type =&gt; Tie::RangeHash::TYPE_NUMBER; $y_ranges-&gt;add(' -500, -101', '-25'); $y_ranges-&gt;add(' -100, -26', '-10'); $y_ranges-&gt;add(' -25, -1', '-5'); $y_ranges-&gt;add(' 0, 25', '5'); $y_ranges-&gt;add(' 26, 100', '10'); $y_ranges-&gt;add(' 101, 500', '25'); $y_ranges-&gt;add(' 501, 1000', '100'); $y_ranges-&gt;add(' 1001, 5000', '250'); $y_ranges-&gt;add(' 5001, 10000','1000'); $y_ranges-&gt;add('10001, 50000','2500'); $y_ranges-&gt;add('50001,' ,'5000'); sub set_y_axis { # This routine over-rides the y_max_value calculation in GD::Graph, which produces double the # required limit, and therefore a lot of white-space... return 1 unless @_ ; #no point going any further if no arguments were provided, however result has to be #non-zero to avoid /0 errors in GD::Graph my @a = map { $_ || 0 } @_ ; #array may have undefs in it. Set null to zero for calc of max my ($y_max) = sort { $b &lt;=&gt; $a } @a ; # Get largest total for y-axis my $y_range = $y_ranges-&gt;fetch($y_max); my $y_axis = ($y_max%$y_range==0) ? $y_max+$y_range : ($y_max - ($y_max%$y_range) + $y_range); sprintf("%d", $y_axis); } sub my_graph { my @ymax; # generate data... foreach loop etc push(@ymax, $this_y_value); # append y-value or cumulative y-value as appropriate # etc. my $graph = GD::Graph::lines-&gt;new(750, 280); $graph-&gt;set( y_max_value =&gt; set_y_axis(@ymax), x_labels_vertical =&gt; 1, transparent =&gt; 1, # etc ); # etc } </code></pre> <p>Hope that's useful to you.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload