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

Thanks a lot, your solution works for me. Just i am making the graph more attractive now, I am putting values on the top of each bar. But for some values when your run below code you will see like 30, 50 and 90 these numbers are not visible properly. And also i don't want 0 to show there. Can you please help me in this
#!/usr/bin/perl use strict; use GD; use GD::Graph::mixed; use GD::Graph::colour; use GD::Graph::bars; use GD::Graph::hbars; use GD::Graph::Data; use GD::Text; use GD::Graph::pie; #use GD::Font; my @data = ( ['Mon','-','Tues','-','Wed','-'], [10,0,40,0,80,0], [30,0,50,0,90,0], [0,100,0,60,0,30], [0,60,0,70,0,50], ); my @names = qw/sample15 sample15-h/; for my $my_graph (GD::Graph::bars->new, GD::Graph::hbars->new) { my $name = shift @names; print STDERR "Processing $name\n"; $my_graph->set( x_label => 'Days', y_label => 'CPU Utilization', y_min_value => 0, y_max_value => 200, #title => 'Stacked Bars (incremental)', cumulate => 1, #overwrite => 1, x_label_position => 1/3, #borderclrs => $my_graph->{dclrs}, dclrs => [ qw( green dgreen yellow dyellow ) ], transparent => 0, show_values => 1, values_space => 1, bar_spacing => 2, bargroup_spacing => 4, accent_treshold => 200, ); $my_graph->set_values_font('/usr/lib/perl5/5.8.8/fonts/nimbus_roman_ +i.pfb', 8); $my_graph->set_legend( qw(E-Avg E-Max T-Avg T-Max)); my $gd = $my_graph->plot(\@data); open(IMG, '>',$name.'.gif') or die $!; binmode IMG; print IMG $gd->gif; close IMG; }
  • Comment on Re^5: GD::Graph creating a clustered bar chart while some dataset are cumulative
  • Download Code

Replies are listed 'Best First'.
Re^6: GD::Graph creating a clustered bar chart while some dataset are cumulative
by poj (Abbot) on Aug 29, 2013 at 13:13 UTC

    Use undef in place of zero in your data

    my @data = ( ['Mon','-','Tues','-','Wed','-'], [10,undef,40,undef,80,undef], [30,undef,50,undef,90,undef], [undef,100,undef,60,undef,30], [undef,60,undef,70,undef,50], );
    poj
      Hi Poj, that works for me, thanks. Now, I want 1 more graph with 3 stack bars. I have tried this by providing data in below format but its not working. Can u please help
      my @data = ( ['Mar1','Mar2','Mar3','Apr1','Apr2','Apr3','May1','May2','May3], [1,0,2,0,4,0], [2,0,1,0,5,0], [0,3,0,3,0,6], [0,4,0,4,0,7], [3,0,4,0,5,0], [0,0,0,0,0,0], );
        You need 9 data points, try
        my @data = ( ['Mar1','Mar2','Mar3','Apr1','Apr2','Apr3','May1','May2','May3], [1,0,0,2,0,0,4,0,0], [2,0,0,1,0,0,5,0,0], [0,3,0,0,4,0,0,6,0], [0,4,0,0,3,0,0,7,0], [0,0,5,0,0,6,0,0,1], [0,0,6,0,0,5,0,0,2], );
        poj