in reply to Re: 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

I Have tried with my below code as you have said, but its not working. Can you please help me and let me know where i am doing wrong.
use GD::Graph::bars; use GD::Graph::hbars; require '/root/.cpan/build/GDGraph-1.48/samples/save.pl'; my @data = ( ["1st","2nd"], [ (3.75,10),(3.75,12) ], [ (4.25,3),(4.25,7) ], ); 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 => 'X Label', y_label => 'Y label', title => 'Stacked Bars (incremental)', #y_max_value => 50, #y_tick_number => 10, #y_label_skip => 2, cumulate => 4, overwrite => 1, borderclrs => $my_graph->{dclrs}, #cycle_clrs => 4, bar_spacing => 2, #shadow_depth => 4, transparent => 0, ); $my_graph->set_legend( qw(offset increment more)); $my_graph->plot(\@data); save_chart($my_graph, $name); }
  • Comment on Re^2: GD::Graph creating a clustered bar chart while some dataset are cumulative
  • Download Code

Replies are listed 'Best First'.
Re^3: GD::Graph creating a clustered bar chart while some dataset are cumulative
by BrowserUk (Patriarch) on Aug 28, 2013 at 10:08 UTC
    I Have tried with my below code as you have said, but its not working.

    I ran your code and it produced this and this which looks pretty much exactly how I envisioned it would.

    So, how is it "not working"?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      But i want multi-stacked graph, like you have said before i.e in my 1st set of x-axis it should contain both the bars, with different colors. i.e ABCD all with different colors in 1 set as your example shows ABCD all in 4th set.
      25| | 20| B | B 15| B | B 10| A D | A D 5| A D | A C 0+------------------------------------------------- 1 2 3 4 5 6 7 8 9 10 11 12

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

        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        If you want different colours then you could create a 4 stack bar but use only 2 of the stack, the other 2 set to zero and alternate the 2 used. For example ;

        #!perl use GD::Graph::bars; use GD::Graph::hbars; my @data = ( ['Mar1','Mar2','Apr1','Apr2','May1','May2'], [1,0,2,0,4,0], [2,0,1,0,5,0], [0,3,0,3,0,6], [0,4,0,4,0,7], ); 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 => 'X Label', y_label => 'Y label', title => 'Stacked Bars (incremental)', cumulate => 1, overwrite => 1, borderclrs => $my_graph->{dclrs}, bar_spacing => 5, transparent => 0, ); $my_graph->set_legend( qw(A B C D)); my $gd = $my_graph->plot(\@data); open(IMG, '>',$name.'.gif') or die $!; binmode IMG; print IMG $gd->gif; close IMG; }
        poj
        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; }