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; } #### 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 );