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

Am trying to graph about 590 data points on a line graph. The output shows a large black rectangle. What am I doing wrong:
sub graphtest { $my_graph = new GD::Graph::lines(800, 600); my $data = new GD::Graph::Data( [ @{$dataarrays{'time'}} , @{$dataarrays{'page ins (x1000)'}} # , @{$dataarrays{'cpu system %'}}, ] ); $my_graph->set( x_label => 'Time', # y_label => 'Y label', title => 'Load Analysis '.$store, y_max_value => 100, y_tick_number => 6, y_label_skip => 2, x_label_skip => 20, transparent => 0, ); # $my_graph->set_legend( 'page ins (x1000)' ); $my_graph->plot(\@data); &save_chart($my_graph, $receivedir . 'loadanalysis'); } #----------------------------------------------------- # sub save_chart { my $chart = shift or die "Need a chart!"; my $name = shift or die "Need a name!"; local(*OUT); open(OUT, ">$name.gif") or die "Cannot open $name.gif for write: $!"; binmode OUT; print OUT $chart->gd->gif(); close OUT; }
A dump of %dataarrays shows it to be, apparently, ok. Any suggestions?
pat

Replies are listed 'Best First'.
Re: GD Graph: gif comes out a large black rectangle.
by zentara (Cardinal) on May 04, 2005 at 12:25 UTC
    I run into that all the time, because I use a black desktop background. (Although your problem may be caused elsewhere.) Try these extra settings:
    $graph->set( transparent => '0', bgclr => 'lgray', boxclr => 'white', fgclr => 'white', x_label => 'X Label', y_label => 'Y label', title => 'Some simple graph', y_max_value => 8, y_tick_number => 8, y_label_skip => 2 ) or die $graph->error;

    I'm not really a human, but I play one on earth. flash japh
      Scott (5miller) suggested much the same. I'll try your code and see what happens. Thanks!!
      pat
      Tried adding color attribute definitions but still comes out all black. Tried jpeg, and not loading any data. Still a very nice black rectangle. Any other suggestions???
      pat
Re: GD Graph: gif comes out a large black rectangle.
by 5mi11er (Deacon) on May 04, 2005 at 15:15 UTC
    The thing that jumped out at me as I read your code was that you weren't specifying what colors to use. So, whatever the 'default' color was, in this case, as you say, it appears that color is black, the background, text and graphed information (points, lines, bars, whatever) will all be black...

    -Scott

Re: GD Graph: gif comes out a large black rectangle.
by thcsoft (Monk) on May 04, 2005 at 05:12 UTC
    hmm... as far as i can see your code seems to be ok. did you try another format, gd->png for instance?
    language is a virus from outer space.
      I did try png but got an error message... That's for another day ;-)
      pat