in reply to What do I need to add?

I think that this is what you were looking for. You were missing the save_chart sub, and the script saves the chart as a gif (by default):
#!/usr/bin/perl use strict; use warnings; use GD::Graph::bars; use GD::Graph::hbars; use GD::Graph::Data; my $data = GD::Graph::Data->new([ ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], [23, 5, 2, 20, 11, 33, 7, 31, 77, 18, 65, 52]]); my $mygraph = GD::Graph::bars->new(500, 300); $mygraph->set( x_label => 'Month', y_label => 'Number of Hits', title => 'Number of Hits in Each Month in 2002', ) or warn $mygraph->error; $mygraph->plot($data) or die $mygraph->error; save_chart($mygraph, 'test'); sub save_chart { my $chart = shift or die "Need a chart!"; my $name = shift or die "Need a name!"; local(*OUT); my $ext = $chart->export_format; open(OUT, ">$name.$ext") or die "Cannot open $name.$ext for write: + $!"; binmode OUT; print OUT $chart->gd->$ext(); close OUT; }
Note that my @data = ([ should be
my $data = GD::Graph::Data->new([
Updated: Noticed something missing? Here's the corrected chart:
#!/usr/bin/perl use strict; use warnings; use GD::Graph::bars; use GD::Graph::hbars; use GD::Graph::Data; my $data = GD::Graph::Data->new([ ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], [23, 5, 2, 20, 11, 33, 7, 31, 77, 18, 65, 52]]) or warn GD::Graph::Data->error; for my $mygraph (GD::Graph::bars->new(500, 300), GD::Graph::hbars->new(500, 300) { my $name = 'test'; print STDERR "Processing $name\n"; $mygraph->set( x_label => 'Month', y_label => 'Number of Hits', title => 'Number of Hits in Each Month in 2002', bar_spacing => 8, shadow_depth => 4, shadowclr => 'dred', transparent => 0, ) or warn $mygraph->error; $mygraph->plot($data) or die $mygraph->error; save_chart($mygraph, $name); } sub save_chart { my $chart = shift or die "Need a chart!"; my $name = shift or die "Need a name!"; local(*OUT); my $ext = $chart->export_format; open(OUT, ">$name.$ext") or die "Cannot open $name.$ext for write: + $!"; binmode OUT; print OUT $chart->gd->$ext(); close OUT; }