Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to plot a simple line graph on a web page using the GDGraph module. So far all i seem to get after i ran my script is an empty image My code is as follows:
#!/usr/local/bin/perl5 use GD::Graph; use GD::Graph::lines; use CGI; my $query = new CGI; @data = ( ["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"], [ 1, 2, 5, 6, 3, 1.5, 1, 3, 4], [ sort { $a <=> $b } (1, 2, 5, 6, 3, 1.5, 1, 3, 4) ] ); my $format; print "Content-type: image/png\n\n"; # create a new graph my $graph = GD::Graph::lines->new(400,400); $graph->set( x_label => 'X Label', y_label => 'Y label', title => 'Some simple graph', ); $format = $graph->export_format; print $query->header("image/$format"); binmode STDOUT; #(the parentheses after $format are necessary, to help the compiler + decide that # you mean a method name here) print $graph->plot(\@data)->$format();

Replies are listed 'Best First'.
Re: GDGraph charts
by btrott (Parson) on Jul 17, 2000 at 22:59 UTC
    I'm not sure of your exact error, here, because it's very hard to see what's in the @data array (use <code> tags!).

    But you're printing out the header twice... did you see that? First you print it out by hand, then you print it out using CGI::header. Take one of those out. Also check to see that @data has what you think it should.

(chromatic) Re: GDGraph charts
by chromatic (Archbishop) on Jul 18, 2000 at 02:46 UTC
    Apologies if this is an incredibly stupid comment, but my documentation suggests a slightly different approach:
    my $image = $graph->plot(\@data); print $image->png;
    (Code taken from the 2nd edition of Programming CGI with Perl.)