Listing of GIF_BARSBYDAY.ASP

This is a listing of the script that generates a bar chart for each record. The calling page calls this script with a URL variable called "Day", which is used to select the correct record from the database.

The csDrawGraph AddData method is called for each field. The data value is read directly from the database and it is important to use the CInt( ) function to prevent a type mismatch error. It uses all the default property settings which simplifies the script although it could be preferable to specify the top of the YAxis and the graduations (YTop and YGrad) to ensure that each graph uses the same scale.

Set Chart = Server.CreateObject("csDrawGraphTrial.Draw")

ConnectionString = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & _
  Server.MapPath("data.mdb")
Set DBConn = Server.CreateObject("ADODB.Connection")
DBConn.Open ConnectionString
Set RS = Server.CreateObject("ADODB.Recordset")
SQL = "SELECT * FROM Table1 WHERE Day=" & Request.QueryString("Day")
RS.Open SQL, DBConn

Chart.AddData "Red", CInt(RS("Red")), "ff0000"
Chart.AddData "Blue", CInt(RS("Blue")), "0000ff"
Chart.AddData "Green", CInt(RS("Green")), "00ff00"
Chart.AddData "Yellow", CInt(RS("Yellow")), "ffff00"
Chart.Title = "Results for day " & Request.QueryString("Day")
Chart.TitleX = 100

RS.Close
DBConn.Close

Response.ContentType = "image/gif"
Response.BinaryWrite Chart.GIFBar