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.
|