in reply to Re^4: GD::Graph creating a clustered bar chart while some dataset are cumulative
in thread GD::Graph creating a clustered bar chart while some dataset are cumulative
Try this (produces this):
use Data::Dump qw[ pp ]; use GD::Graph::bars; use GD::Graph::hbars; my @data = ( [ qw[Jan _ Feb _ Mar _ Apr _ May _ Jun _ Jul _ Aug _ Sep _ Oct _ N +ov _ Dec _ ] ], [ map rand( 25 ), 1 .. 24 ], [ map rand( 25 ), 1 .. 24 ], ); for my $my_graph (GD::Graph::hbars->new( 800, 600 ) ) { $my_graph->set( title => 'Stacked Bars (incremental)', x_label => 'X Label', y_label => 'Y label', cumulate => 1, overwrite => 1, borderclrs => $my_graph->{dclrs}, bar_spacing => 20, bar_width => 10, transparent => 0, ); $my_graph->set_legend( qw(offset increment more)); $my_graph->plot(\@data); save_chart($my_graph, "test.png"); } system 1, 'test.png'; sub save_chart { my $chart = shift or die "Need a chart!"; my $name = shift or die "Need a name!"; local(*OUT); open(OUT, ">$name") or die "Cannot open $name.$ext for write: $!"; binmode OUT; print OUT $chart->gd->png; close OUT; }
|
|---|