Vertical Graphing of Database DataBy Jim Rudnick
|For More Information...|
|For more information on graphing with ASP be sure to check out our Graphing with ASP Article Index!|
Recently a client asked me if I could "graph" their divisional standings on a Web page for their automotive division. At first thought, this seemed relatively easy, till I got well into the project! Figuring on sourcing some code for what I needed from the Web led only to a half a day of searching and reading and then downloading of code that wasn't at all right till I finally realized that I'd have to do the basic work myself...sigh, so much for easy street on this one!
What follows then herein is a look at what I'd planned and then what code I wrote to enable just such a graphic layout for the client and how it all came together.
First of all, the graphics. If you're looking at them right now in the screenshot below, you'll note that they are just terrible, and isn't that the truth. These are substituted graphics from what I used for the client, as is the small database I've included herein for this article only. Please do realize that you can use your own graphics for the cars used here -- although you may want to change the paradigm from my own "cars-on-a-garage-hoist" one to one of your own.
Obtaining the Raw Database Data
Enough said up front, lets move to the code. You will note that I've made a DNS-less connection to the database that is held in name by the variable called
dbName, and I create a select statement (SQL) that asks for
all the data in the dbase table named
This database table holds only the names of the divisions, and their current percentages. While this is a simple
database, it could be as
involved as you need it in the real world. And while for purposes of ease of explanation, I'm using an Access
database here, the same items could be pulled from an SQL dbase too, if that was what you're using. (You can
download the Access database (along with the support files) at the
end of this article...)
So far we've just looked at code to get us started by grabbing the appropriate database table. In Part 2 we'll continue our examination of this ASP script and look at how this raw data can be turned into a fancy graph!