Listing of GIF_BARSBYCOLOUR.ASP

This is a listing of most of the script that produces all 4 bar charts. The calling page has 4 <img> tags, each calls this script with a URL variable called "Colour". This script uses that URL variable to determine the bar colours and also to construct the SQL statement that reads the database. That is how 4 different graphs are produced from one script.

The images produced have a smaller width than default and a number of component properties are changed to allow for this. Also the background colour is a light grey and this value must be used for the background of the different text items.

Select Case Request.QueryString("Colour")
  Case "Red" : Colour = "ff0000"
  Case "Blue" : Colour = "0000ff"
  Case "Green" : Colour = "00ff00"
  Case "Yellow" : Colour = "ffff00"
End Select

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 Day, " & Request.QueryString("Colour") & " FROM Table1 ORDER BY Day"
RS.Open SQL, DBConn

'The day, the value and the colour are added for each record
'The CInt( ) function is needed to prevent a type mismatch error
'The data value is read using RS.Fields(1) because it is the second field
'in the recordset

While Not RS.Eof
  Chart.AddData CInt(RS("Day")), CInt(RS.Fields(1)), Colour
  RS.MoveNext
Wend

RS.Close
DBConn.Close

Chart.Title = "Results for " & Request.QueryString("Colour")
Chart.TitleX = 100
Chart.Width = 300
Chart.MaxX = 220
Chart.XAxisText = "Days"
Chart.YAxisText = "Total"
Chart.ShowLegend = false
Chart.BGColor = "eeeeee"
Chart.PlotAreaColor = "eeeeee"
Chart.TitleBGColor = "eeeeee"
Chart.LabelBGColor = "eeeeee"
Chart.AxisTextBGColor = "eeeeee"

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