<% Sub ShowChart(ByRef Match, ByRef strTitle, ByRef strXAxisLabel, ByRef strYAxisLabel, ByRef aAltData) Dim aValues(2), aLabels(2) Sql= "SELECT Count(*) as cnt, " & Match & " as wwf FROM tblVote where " & Match & " is not null GROUP BY " & Match Set rs= cn.Execute(Sql) Do while NOT rs.EOF total=total+rs(0) 'get a total of responses rs.movenext loop rs.movefirst Do while not rs.eof intPercent=Cint((rs(0)/total)*100) aValues(n)=intPercent aLabels(n)=rs(1) n=n+1 rs.movenext loop set rs=nothing ' Some user changable graph defining constants ' All units are in screen pixels Const GRAPH_WIDTH = 70 ' The width of the body of the graph Const GRAPH_HEIGHT = 55 ' The heigth of the body of the graph Const GRAPH_BORDER = 5 ' The size of the black border Const GRAPH_SPACER = 2 ' The size of the space between the bars ' Debugging constant so I can eaasily switch on borders in case ' the tables get messed up. Should be left at zero unless you're ' trying to figure out which table cells doing what. Const TABLE_BORDER = 0 'Const TABLE_BORDER = 10 ' Declare our variables Dim I Dim iMaxValue Dim iBarWidth Dim iBarHeight ' Get the maximum value in the data set iMaxValue = 0 For I = 0 To UBound(aValues) If iMaxValue < aValues(I) Then iMaxValue = aValues(I) Next 'I 'Response.Write iMaxValue ' Debugging line ' Calculate the width of the bars ' Take the overall width and divide by number of items and round down. ' I then reduce it by the size of the spacer so the end result ' should be GRAPH_WIDTH or less! iBarWidth = (GRAPH_WIDTH \ (UBound(aValues) + 1)) - GRAPH_SPACER 'Response.Write iBarWidth ' Debugging line ' Start drawing the graph %>
<%= strTitle %>
<%= strYAxisLabel %>
<% ' We're now in the body of the chart. Loop through the data showing the bars! For I = 0 To UBound(aValues)-1 iBarHeight = Int((aValues(I) / iMaxValue) * GRAPH_HEIGHT) ' This is a hack since browsers ignore a 0 as an image dimension! If iBarHeight = 0 Then iBarHeight = 1 %> <% Next 'I %> <% ' The label array is optional and is really only useful for small data sets with very short labels! %> <% If IsArray(aLabels) Then %> <% For I = 0 To UBound(aValues)-1 %> <% Next 'I %> <% End If %>
<%= aValues(I) %>
<%= aLabels(I) %>
<%= strXAxisLabel %>
<% End Sub %>