<%@ LANGUAGE="VBSCRIPT" %> <% Option Explicit %> <% 'How many pixels high we want our bar graph Const graphHeight = 300 Const graphWidth = 450 Const barImage = "bluebar.gif" sub BarChart(data, labels, title, axislabel) 'Print heading Response.Write("" & chr(13)) Response.Write("" & chr(13)) Response.Write("") Dim widthpercent widthpercent = CInt((1 / (UBound(data) - LBound(data) + 1)) * 100) For i = LBound(data) to UBound(data) - 1 Response.Write(" " & chr(13)) Next Response.Write("") Response.Write("") 'Write footer Response.Write("" & chr(13)) for i = LBound(labels) to UBound(labels) - 1 Response.Write("" & chr(13)) next Response.Write("" & chr(13)) Response.Write("
") Response.Write("" & title & "
" & chr(13)) 'Find the highest value Dim hi hi = data(LBound(data)) Dim i for i = LBound(data) to UBound(data) - 1 if data(i) > hi then hi = data(i) next 'Print out the highest value at the top of the chart Response.Write(hi & "" & chr(13)) Response.Write(" " & chr(13)) Response.Write("
0
" & axislabel & "" & labels(i) & "
") end sub 'Open connection to database Dim objConnection Set objConnection = Server.CreateObject("ADODB.Connection") objConnection.Open "DSN=Products" Dim strSQL strSQL = "SELECT Name,UnitsSold FROM Products" Dim rsProducts Set rsProducts = Server.CreateObject("ADODB.Recordset") rsProducts.Open strSQL, objConnection, adOpenStatic Dim numRecords numRecords = rsProducts.RecordCount Dim unitsSoldArray(), labelArray() Redim unitsSoldArray(numRecords) Redim labelArray(numRecords) Dim i for i = 0 to numRecords-1 unitsSoldArray(i) = rsProducts("UnitsSold") labelArray(i) = rsProducts("Name") rsProducts.MoveNext next %>
<% BarChart unitsSoldArray,labelArray,"Units Sold","Product" %>
<% rsProducts.Close Set rsProducts = Nothing objConnection.Close Set objConnection = Nothing %>