Enclosed a couple of code snippets from a stat. program I currently have in production, that might help you.
You have to explicitly calculate the Y min and max from your data sets, and then set the graph y_min_value and y_max_value options accordingly to scale the graph.

<more> You may chose to do this in a plot 'wrapper' function.
### ====================================================== ### UTIL: plot (using GD::Graph::$type) ### ====================================================== sub plot { ### Set options for graph, cf params and default my ($rOpt, $rData, $type, $x, $y) = @_; # %Opt, @data, ... $type ||= 'hb'; # Default horiz. bars $x ||= max(scalar(@{$rData->[1]})*20, 150); # Scale to num. data.p +ts $y ||= 400; # Fixed (dyn: max(ceil +($s/2), 400);) my @opt = %{$rOpt}; # Flatten option hash +to array my $graph; # (width:y, height:x) if ($type eq 'lp') { $graph = GD::Graph::linespoints->new($y, $x); + } if ($type eq 'hb') { $graph = GD::Graph::hbars->new($y, $x); } $graph->set_x_axis_font(gdTinyFont); $graph->set(logo => ".\\KMD.gif", logo_resize => 0.5, logo_position => "LL", ); $graph->set(@opt) or die $graph->error; ### Plot graph, cf @$rData array my $gd = $graph->plot($rData) or die $graph->error; my $dir = Win32::GetCwd() . "\\plot"; unless (-e $dir and -d $dir) { mkdir($dir) or die "can't mkdir $di +r: $!"; } open(IMG, ">$dir\\$rOpt->{title}.png") or die "can't open $dir\\$t +.png: $!"; binmode IMG; print IMG $gd->png; }
Example of calling the plot util function:
### ------------------------------------------------------ ### Plot SDPI-$y-$mm-Load-($avg[0],$avg[1]) my $max = max(@{$data[1]},@{$data[2]}); # max val. data pt. $avg[0] = sum(@{$data[1]})/scalar(@{$data[1]}); $avg[1] = sum(@{$data[2]})/scalar(@{$data[2]}); $avg = sprintf( "%.1f,%.1f", $avg[0],$avg[1] ); my %opt = ( title => "SDPI-$y-$month[0][$m]-Load-($avg)", x_label => "Hour / Day", y_label => 'Forms/Min: Avg.(green) & Max(red)', y_min_value => 0, y_max_value => $max+1, #ceil($max + $max*0.1), y_tick_number => $max+1, y_number_format => "%3d", two_axes => 1, show_values => 1, values_vertical => 1, values_space => 8, ); plot(\%opt, \@data, 'lp', 400); # Float $opt{title} .= '-'; # Fixed $opt{y_max_value} = $opt{y_tick_number} = 40; plot(\%opt, \@data, 'lp', 400);
</more> Best regards
allan

In reply to Re: GD module doubt by ady
in thread GD module doubt by sanku

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.