I'm not sure what is causing the error you are seeing, but I can suggest the following variation that might work for you:
sub draw_graph { my ( $filename, @data ) = @_; my $graph = new GD::Graph::histogram( 400, 600 ); $graph->set( x_label => 'Data', y_label => 'Count', title => 'A Histogram Chart', x_labels_vertical => 1, bar_spacing => 0, shadow_depth => 1, shadowclr => 'dred', transparent => 0, ) or warn $graph->error; my $gd = $graph->plot( \@data ) or die $graph->error; open( IMG, '>' . $filename ) or die $!; binmode IMG; print IMG $gd->png; }
The difference being that the graph object does not have to be passed around, since it would appear that it is only being generated and written out. To call this, you might do something like the following examples:
foreach ( 1, 5, 7, 8, 9, 10, 11, 3, 3, 5, 5, 5, 7, 2, 2 ) { push( @data, $_ * ( $_ + 1 ) ); } draw_graph( 'test1.png', @data ); @data = ( 1, 5, 7, 8, 9, 10, 11, 3, 3, 5, 5, 5, 7, 2, 2 ); draw_graph( 'test2.png', @data );
HTH.
In reply to Re^3: Histogram in Perl
by atcroft
in thread Histogram in Perl
by Jaya
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |