Dear Monks,

I've been messing around with GD::Graph for a while as an option for dynamically serving up some graphs via a CGI script. For the most part I'm happy, it runs pretty fast and gives me pretty pictures. I have encountered some strange behavior with data running off the graph... for simplicity, here is an example of a very basic graph that works normally:
use strict; use GD::Graph::lines; my @data = ( [1, 2, 3, 4, 5, 6, 7, 8, 9,], [ 8, 8.25, 8.5, 8.35, 8.76, 8.21, 8.6, 8.8, 8.5], [ 7.4, 7.6, 7.8, 7.9, 7.4, 8.5, 7, 7.87, 8.34], [ 4, 5, 6, 5.6, 5.5, 6.1, 6.3, 5.2, 5.6]); my $graph = new GD::Graph::lines (600, 400); $graph->set( title => "Blah, Blah, Blah", x_label => 'X axis label', y_label => 'Y axis label', boxclr => '#C0C0C0' ); ## Next code snippet goes here $graph->set_legend("data set 1", "data set 2", "data set 3"); print "Content-type: image/png\n\n"; binmode(STDOUT); print $graph->plot(\@data)->png();
Now lets say you want to allow the user to "zoom in" on an area of the graph. Pretend that after some CGI magic and some passed parameters, the min/max for the x and y axes are as follows and you insert this code where I have marked in the above script:
$graph->set( y_min_value => 6, y_max_value => 10, x_min_value => 3, x_max_value => 7 );
The lines run off the edge of the x and y axes, the x_max_value does not appear to be properly set, etc. Am I dumb and have an error in the code somewhere or do you folks encounter the same problem? Could be a better looking graph, eh? Didn't find a fix for this in the documentation. So far it does this on my Linuxbox (forgot what flavor, I don't manage it), and a WinNT machine, both with what I think is the most recent module of GD::Graph. If this is a known problem and there is a fix, do let me know.

I understand I could modify my data sets so that the data "fits" within the plotting area. But, I'm lazy and I feel like this is something GD::Graph should be able to handle internally. Any wisdom you may offer will be much appreciated.

Thank you,
-C

In reply to GD::Graph - data plotting off the charting area by mgdude

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.