cLive ;-) has asked for the wisdom of the Perl Monks concerning the following question:

This works fine (FreeBSD 4.9, perl 5.8.0, gd-2.0.33_4, GD 2.34):
#!/usr/bin/perl use strict; use warnings; use Data::Dumper 'Dumper'; use GD::Graph::linespoints; my @month = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); my $data= [ [ '1155279600', '1156366000', '1157452400', ], [ '88', '93', '23', ] ]; my %arg = ( marker_size => 1, x_label => 'Date', x_min_value => $data->[0]->[0], x_max_value => $data->[0]->[-1], x_tick_number => 7, x_tick_offset => 1, x_number_format => \&convert_date, y_label => 'Inventory Count', y_tick_number => 5, ); # create graph my $graph = GD::Graph::linespoints->new(750,450); $graph->set(%arg) or die $graph->error.Dumper(\%arg); my $gd = $graph->plot($data) or die $graph->error.Dumper($data); # write graph to disk open(my $graphfile, '>', "/home/clive/public_html/tmp2.png") || di +e $!;; binmode $graphfile; print {$graphfile} $gd->png; close($graphfile); sub convert_date { my $epoch_time = shift; my @t = localtime($epoch_time); return sprintf("%02d %s %d", $t[3], $month[ $t[4] ], $t[5]+1900); }

Creating this image. However, if I switch to GD::Graph::area (which is what I need to use), I get this empty one.

If I then change the data to this:

my $data= [ [ '1', '2', '3', ], [ '1', '2', '3', ] ];

I get a real graph.

No error messages appear at all. I've been scratching my head on this one for an hour. Anyone got any idea what's up?

Replies are listed 'Best First'.
Re: GD::Graph::area failing with no error...
by Khen1950fx (Canon) on Nov 13, 2006 at 08:00 UTC
    I tried to get some documentation on GD::Graph::area, but nothing came up. However, I downloaded the package and looked in the samples directory. I found three samples for GD::Graph::area...

    sample21.pl sample22.pl sample23.pl

Re: GD::Graph::area failing with no error...
by BrowserUk (Patriarch) on Nov 13, 2006 at 23:00 UTC

    From the GD docs:

    For bar and area graphs, the range (y_min_value..y_max_value) has to include 0. If it doesn't, the values will be adapted before attempting to draw the graph.

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      Give that man a cookie! Thanks. I was going nuts there. Time for a quick map and amend of the date_format sub...

      Well, this is slightly better. Now all I have to do is work out how to stretch it to the right. Weird.

      Aha! Adding back in x_max_value is looking almost there.

        One trick you might use, though it is definitely a trick, is to produce your graph much wider than you eventually want it, and then use the GD::Image copying methods to crop out and peice together the pieces you want. Eg.

        | -| | -| ### ### ##### #### | ####### ####### #### -| ##################### | ###################### -+------------------------------'-'-'-'-'-'-'-'-'-'-'-' 0

        then copy the interesting bits of the graph to a new image leaving out the boring bit between the left hand scale and the actual data.

        Hmm. All in all, mapping the data to zero and then mapping it back in the number formating routine makes much more sense :)


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: GD::Graph::area failing - some progress
by cLive ;-) (Prior) on Nov 13, 2006 at 22:14 UTC

    removing:

    x_min_value => $data->[0]->[0], x_max_value => $data->[0]->[-1],

    from the args creates this - a slight improvement.

    But, as you can see, still way off of displaying as expected. I have a feeling it's something to do with the labeling. Oh joy.

    I just ran another test with the live data set. The first graph is as expected, but the ticks are (obviously) wrong. If I add the ticks back in (x_tick_number => 5), I get this instead. Looks like some fundamental error in the area module, maybe?!? Weird...