- customisable colours, fonts and dimensions
- bar or column styles
- gradient fill option for columns and plot area background
- random bar colour feature to easily make multiple graphs on the same page more distinct
- XHTML image map output to enable displaying of values when moving mouse cursor over the bars (see example)
Requirements: Perl and the GD module are needed to run 3DBarGrapher. Development versions were ActivePerl 5.8.4.810 and GD 2.16 but it will likely function correctly with earlier releases.
License: 3DBarGrapher is copyright © 2007 S.I.Warhurst and provided free under the same terms and conditions as Perl itself. See the Perl Artistic license.
Download:
3dbargrapher.zip
DOCUMENTATION
Installation: You can extract 3dbargrapher.pl to wherever you like, however into your Perl installation's /lib/ folder may be easiest.
Usage:
require "3dbargrapher.pl";
my @data = (
['Apples', 28],
['Pears', 43],
...etc
);
my %options = (
'file' => '/webroot/images/mygraph.jpg',
);
my $imagemap = creategraph(\@data, \%options);
The data to graph must be passed in a multidimensional array where column 0 is the x-axis name of the item to graph and column 1 is it's associated numerical value.
Graph options are passed in a hash and override the defaults listed below. At minimum the 'file' option must be included and specify the full path and filename of the graph to create.
There is only one function in the 3dBarGrapher module and that is creategraph which will return image map XHTML for use in a web page displaying the graph.
Options:
my %options = (
# colours
black => { R => 0, G => 0, B => 0 },
white => { R => 255, G => 255, B => 255 },
vltgrey => { R => 245, G => 245, B => 245 },
ltgrey => { R => 230, G => 230, B => 230 },
midgrey => { R => 180, G => 180, B => 180 },
midblue => { R => 54, G => 100, B => 170 },
# file output details
file => '', # file path and name; file extension
# can be .jpg|gif|png
quality => 9, # image quality: 1 (worst) - 10 (best)
# Only applies to jpg and png
# main image properties
imgw => 400, # preferred width in pixels
imgh => 320, # preferred height in pixels
iplotpad => 8, # padding between axis vals & plot area
ipadding => 14, # padding between other items
ibgcol => 'white', # COLOUR NAME; background colour
iborder => '', # COLOUR NAME; border, if any
# plot area properties
plinecol => 'midgrey', # COLOUR NAME; line colour
pflcol => 'vltgrey', # COLOUR NAME; floor colour
pbgcol => 'ltgrey', # COLOUR NAME; back/side colour
pbgfill => 'gradient', # 'gradient' or 'solid'; back/side fill
plnspace => 25, # minimum pixel spacing between divisions
pnumdivs => 6, # maximum number of y-axis divisions
# bar properties
bstyle => 'bar', # 'bar' or 'column' style
bcolumnfill => 'gradient', # 'gradient' or 'solid' for columns
bminspace => 18, # minimum spacing between bars
bwidth => 18, # width of bar
bfacecol => 'midblue', # COLOUR NAME or 'random'; bar face,
# 'random' for random bar face colour
# graph title
ttext => '', # title text
tfont => '', # defaults to gdGiantFont; can specify
# true type font for better quality
tsize => 11, # font point size
tfontcol => 'black', # COLOUR NAME; font colour
# axis labels
xltext => '', # x-axis label text
yltext => '', # y-axis label text
lfont => '', # defaults to gdLargeFont; can specify
# true type font for better quality
lsize => 10, # font point size
lfontcol => 'midblue', # COLOUR NAME; font colour
# axis values
vfont => '', # defaults to gdSmallFont; can specify
# true type font for better quality
vsize => 8, # font point size
vfontcol => 'black', # COLOUR NAME; font colour
);
Notes on options:
- options commented with "COLOUR NAME" expect the name of one of the default colours above, or you can define your own colours by adding new lines in the same format
- overall graph width and height can exceed the preferred values, depending on number of items to graph and the values specified for various settings like bwidth, bminspace, etc
- for better text quality it is recommended to specify true type fonts for options tfont, lfont & vfont. the full path and font file name must be included, eg: 'c:/windows/fonts/verdana.ttf'
- only options that default to empty can be defined as empty
Image Map: The creategraph function returns XHTML code for the image and an associated image map, something like this:
<img src="mygraph.jpg" width="400" height="320" border="0" usemap="#mygraphjpg1179003059" /> <map name="mygraphjpg1179003059" id="mygraphjpg1179003059"> <area shape="rect" coords="67,123,112,245" href="#" title="Apples: 28" /> <area shape="rect" coords="112,75,158,245" href="#" title="Pears: 43" /> ...etc </map>
Bugs: There aren't any known ones but feel free to report any you find and I may (or may not
) fix them!
