sub save_chart { my $chart = shift or die "Need a chart!"; my $name = shift or die "Need a name!"; local(*OUT); my $ext = 'png'; open(OUT, ">$name.$ext") or die "Cannot open $name.$ext for write: $!"; binmode OUT; print OUT $chart->gd->$ext(); close OUT; } use GD::Graph::bars; use GD::Graph::hbars; use GD::Graph::colour; my @data = ( ["name1", "name2", "name3","name4"], [23, 26, 53, 27], [77, 74, 47, 73] ); my @names = qw/sample15 sample15-h/; my $font_dir = '/usr/share/fonts/truetype'; my $font_file = "$font_dir/freefont/FreeSans.ttf"; for my $my_graph (GD::Graph::bars->new, GD::Graph::hbars->new(700,500)) { my $name = shift @names; print STDERR "Creating image\n"; $my_graph->set( bgclr => 'white', box_axis => 0, y_max_value => 100, dclrs => ['#ff782a', '#6daa3a'], title => 'MY_TITLE', bar_width => 10, bar_spacing => 4, y_tick_number => 2, cumulate => 2, borderclrs => $my_graph->{dclrs}, bar_spacing => 4, transparent => 0, x_label_position => 0.5, tick_length => -4, axis_space => 6, x_ticks => 0, bar_spacing => 1, bargroup_spacing => 20, fgclr => '#bbbbbb', axislabelclr => '#333333', labelclr => '#333333', textclr => '#333333', legendclr => '#333333', legend_placement => 'DC', legend_marker_width => 12, legend_marker_height => 12, legend_spacing => 6, long_ticks => 0, borderclrs => [undef] ); $my_graph->set_title_font($font_file, 16); $my_graph->set_x_label_font($font_file, 16); $my_graph->set_y_label_font($font_file, 16); $my_graph->set_x_axis_font($font_file, 11); $my_graph->set_y_axis_font($font_file, 11); $my_graph->set_legend_font($font_file, 11); $my_graph->set_legend(qw(%leg1 %leg2)); $my_graph->plot(\@data); save_chart($my_graph, $name); }