Okay so maybe it's technically a histogram, but whatever it is, this
sample is an easy way to produce a useful graphical representation from
a boring list of numbers. You can get these numbers from wherever you
want, but it expects them to be in an array and simply won't tolerate it
if they're not! It will even do labels for each bar, but this is
limited since it can only handle them nicely with a very small set of
data and even then you need very short labels!
To disable the labels, like in the second graph, just pass the Sub a
non-array parameter for the labels array. It'll ignore anything that's
not an array. If you do want to use the labels, remember to pass the
right number of labels for your data. Too many shouldn't cause anything
to break (except that your labels might not be attached to the right data
if an extra value got inserted somewhere) but too few will definitely
cause it to complain loudly!
Oh and one other thing... don't start passing it negative numbers unless
you want to modify it to accept them! Use it for hit counts or number of
sales or something like that. Browsers don't stretch images well when
you give them negative numbers!
Update: So you want to graph negative numbers huh?
When I wrote the code above I neglected to add support for negative
numbers. For those who are curious, I originally wrote
the code to graph our web site page views for our sales
guys and so negative numbers weren't a concern. Well one
of our visitors who was feeling generous has donated the
code that he wrote to show bar charts that include negative
The code in the attached zip file is a little more complex then the code
above. I've left it pretty much as it was sent to me. As such there are
some include files and functions which may not be used for this sample.
Just ignore anything that you don't find useful. The values in the graph
come from the included database. The data is just made up numbers I typed in.
Oh well enough of my rambling... download
the code (19 KB)
and give it a look. In terms of giving it a look... here's a small screen shot: