Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Stacked Bar

by swagat.siddhartha (Initiate)
on Jun 13, 2011 at 10:13 UTC ( [id://909356]=perlquestion: print w/replies, xml ) Need Help??

swagat.siddhartha has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
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 ww (Archbishop) 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?

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Stacked Bar
by Corion (Patriarch) on Jun 13, 2011 at 11:53 UTC
Re: Stacked Bar
by davido (Cardinal) 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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-19 03:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found