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.


In reply to Re: Stacked Bar by ambrus
in thread Stacked Bar by swagat.siddhartha

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.