Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Syntactic Confectionery Delight
 
PerlMonks  

Stacked Bar

by swagat.siddhartha (Initiate)
on Jun 13, 2011 at 10:13 UTC ( #909356=perlquestion: print w/ replies, xml ) Need Help??
swagat.siddhartha has asked for the wisdom of the Perl Monks concerning the following question:

How do you create a stcked bar chart??

Comment on Stacked Bar
Re: Stacked Bar
by ww (Bishop) on Jun 13, 2011 at 10:29 UTC
    One at a time, take a loose bar off the pile; the first becomes the base of the stack. Each following is placed atop those already moved.

    Perl relevance? Data source? Have you read On asking for help?

      I need to create a stacked bar chart in perl, How do i proceed??

        If you want to use perl to create a stacked bar chart in Excel then Spreadsheet::WriteExcel or (if you're on Windows) Win32::OLE are probably good places to start.

        For anything more specific you'll need to give us a few more hints about what you're actually trying to do.

Re: Stacked Bar
by ambrus (Abbot) on Jun 13, 2011 at 10:59 UTC

    Plot a spiral with gnuplot shows how to make a chart in general. What you called "stacked bar charts" is probably the histogram rowstacked plots of Gnuplot, so let's use those.

    use strict; use warnings; use 5.010; use IO::Handle; use File::Temp "tempfile"; my($T,$N) = tempfile("plot-XXXXXXXX", "UNLINK", 1); for my $g (1..6) { for my $s (1..4) { print $T rand(10/$s), " "; } print $T "\n"; } open my $P, "|-", "gnuplot" or die; printflush $P qq[ unset key set yrange [0:] set style data histogram set style histogram rowstacked set style fill solid 0.5 set boxwidth 0.9 plot for [COL=1:4] "$N" using COL ]; <STDIN>; close $P; __END__

    Update: see some of these examples of histogram plots of gnuplot webpage.

    Update: here's an example output to dumb terminal with the following extra options:

    set terminal dumb set boxwidth 0.8
    The data is random so your output may differ.
    14 ++--------+---------+---------+---------+---------+---------+--- +-----++ + + + + + + + + + | %%%%%%%% +% | | %%%%%%%%% % +% | 12 ++ % % % +% ++ | % % % +% | | %%%%%%%%% %%%%%%%%% % % $$$$$$$$ +$ | | % % % % % % $ +$ | 10 ++ $$$$$$$$$ % % $$$$$$$$$ $ +$ ++ | $ $ $$$$$$$$$ $ $ $ +$ | | $ $ ######### $ $ ######## +# | | $ $ ********* %%%%%%%%% $ $ # +# | 8 ++ $ $ * * %%%%%%%%% % % $ $ # +# ++ | $ $ * * ######### $$$$$$$$$ ######### # +# | | ######### * * # # $ $ # # # +# | | # # * * # # ######### # # # +# | 6 ++ # # * * # # # # # # # +# ++ | # # * * # # # # # # # +# | | ********* * * # # # # ********* # +# | | * * * * ********* # # * * ******** +* | 4 ++ * * * * * * ********* * * * +* ++ | * * * * * * * * * * * +* | | * * * * * * * * * * * +* | | * * * * * * * * * * * +* | 2 ++ * * * * * * * * * * * +* ++ | * * * * * * * * * * * +* | | * * * * * * * * * * * +* | + * + * * + * * + * * + * * + * * + +* + 0 ++----*********-*********-*********-*********-*********-******** +*----++ -1 0 1 2 3 4 5 + 6

    Update: just to clarify, gnuplot (and the above code example) can produce plots to multiple graphic devices, not only plain ascii drawings like the above example output. The code above does not set the output device so gnuplot will choose an approperiate one, most likely one that draws graphics in a window if you're running it under X or Windows. It can also draw to several saved graphics formats, such as png (raster image) or pdf (vector image) if you tell it so.

Re: Stacked Bar
by Corion (Pope) on Jun 13, 2011 at 11:53 UTC
Re: Stacked Bar
by davido (Archbishop) on Jun 13, 2011 at 15:41 UTC

    Hi swagat.siddhartha, and welcome to the Monastery. The first question you posted here hasn't gone so well. Here is why:

    Monks are really good at Perl, and even somewhat good at things peripheral to Perl. But they're not good at guessing what you mean. In the case of your question you have to define what platform your bar chart is to target (web/cgi, web/some-framework, excel spreadsheet, Tk-environment, pure-text, GD, etc. Next, we need to know where you are currently in the project; do you just have raw data and no Perl program at all? What does the data-set look like? Preferably you've already started into a script but just got stuck somewhere. If that's the case, you would want to post a minimal amount of relevant code for us to help you with.

    You should also let us know if you have a strategy for your program. How have you thought you would like to work it out?

    And it's helpful to know (though we can sometimes guess this part) about your programming background and your background with Perl.

    We love to be helpful, but we're not a script writing service. Our primary goal is to help you to learn. But you have to help us to do that.


    Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://909356]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2014-04-19 21:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (483 votes), past polls