huzefa52 has asked for the wisdom of the Perl Monks concerning the following question:

The GD::Graph doc shows how to cumulate more than one dataset into a single column in a barchart by setting cumulate => 1 But, I have 4 datasets say, A, B, C, D. I want datasets A and B cumulated (stacked on top of each other). Similarly, datasets C and D cumulated as well. The two stacked columns should appear next to each other. In other words, each X-axis value will have 2 columns, each column representing two datasets. Is this possible using GD:Graph? If not, is there a workaround to get this done? Thanks!
  • Comment on GD::Graph creating a clustered bar chart while some dataset are cumulative

Replies are listed 'Best First'.
Re: GD::Graph creating a clustered bar chart while some dataset are cumulative
by BrowserUk (Patriarch) on Aug 27, 2013 at 14:10 UTC
    Is this possible using GD:Graph?

    No. There is no facility in the module for that.

    If not, is there a workaround to get this done?

    A work-around would be to give datasets A & B different X values to datasets C & D and use custom labels to tie them together.

    Ie. If (say) for April the values were: a(4,10), b(4,12), c(4,3), d(4,7) then adjust them so that they become a(3.75,10),b(3.75,12), c(4.25,3), d(4.25,7).

    That way, with cumulate enabled you should get:

    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

    Update: For hbar graphs it would be the Y values you adjust.


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