ASP 101 - Active Server Pages 101 - Web06
The Place ASP Developers Go!

Please visit our partners


Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash





Script Output:

Chart Title

Y Label
55 
6 10 12 18 23 26 27 28 30 34 37 45 55
P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13

X Label



Chart of 50 Random Numbers

Value
50 
23 5 10 13 37 18 30 44 44 20 15 24 1 9 27 17 4 12 37 45 14 18 33 32 37 18 40 1 25 21 39 45 39 15 17 41 14 3 19 50 4 47 12 10 20 24 16 2 47 49

Index

ASP HTML Download            FAQ

ASP.NET Version

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

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:

Bar Chart (Negative) Screen Cap
Samples

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers