Needs ghostscript installed, produces a file "tmp.png".
#!/usr/bin/perl -w
%stats = (Foo => 14, Bar => 10, Baz => 5, Box => 8);
$title = "Widgets, Inc";
$ps_preamble = <<PS_END;
%!PS-Adobe-2.0
/big /Helvetica findfont 20 scalefont def
/tiny /Helvetica findfont 9 scalefont def
/box { newpath moveto lineto lineto lineto closepath } def
0 setgray
big setfont
612 ($title) stringwidth pop sub 2 div
648 moveto
($title) show
1 setlinewidth
72 72 72 720 540 720 540 72 box stroke
tiny setfont
PS_END
open (GS, "|gs -dSAFER -dBATCH -dNOPAUSE -q -r80 -sDEVICE=png16m".
" -sOutputFile=tmp.png - ") or die "Can't start Ghostscript"
+;
print GS $ps_preamble;
my $n = keys %stats;
my $w = 396/$n;
my $i=0;
for (keys %stats)
{
my $x = $i*$w+126; my $y = $stats{$_} * 30 + 108;
print GS "$x 90 moveto\n($_) show\n";
print GS "0.5 0 0.8 setrgbcolor\n";
print GS "$x 108 ",
"$x $y ",
$x+$w/2, " $y ",
$x+$w/2, " 108 box fill\n";
print GS "0 setgray\n";
$i++;
}
print GS "showpage\n";
close(GS);
-- All code is 100% tested and functional unless otherwise noted.
|