<%
function makechart(title, numarray, labelarray, color, bgcolor,outlineborder,barBorder, maxheight, maxwidth, addvalues,linkTo)
' numarray: An array of values for the chart
' labelarray: An array of labels coresponding to the values must be present
' color: If null uses different colors for bars if not null all bars are color you specify
' bgcolor: Background color.
' outlineborder: Border size or 0 for no border for outline table.
' barborder: Border size for bars - needed for browsers with no table background colour.
' maxheight: Maximum height for chart not including labels
' maxwidth: Width of each column
' addvalues: True or false depending if you want the actual values shown on the chart
'
' when you call the function use : response.write makechart(parameters)
dim tablestring 'actually returnstring would be a better name
dim max 'max value is maximum table value
dim maxlength 'maxlength maximum length of labels
dim tempnumarray
dim templabelarray
dim heightarray
Dim colorarray
Dim multiplier 'value to multiplie chart values by to get relitive size
gotData = false
for each thing in numarray
If len(thing) > 0 Then gotData = true
next
' start table
tablestring = "" & vbcrlf
tablestring = tablestring + " " & _
"" & vbCrLf
'if data valid
If maxheight > 0 And maxwidth > 0 And UBound(labelarray) = UBound(numarray) And gotData Then
'colorarray: color of each bars if more bars then colors loop through
'if you don't like my choices change them, add them, delete them.
colorarray = array("red","blue","yellow","navy","orange","purple","green")
templabelarray = labelarray
tempnumarray = numarray
heightarray = array()
max = 0
maxlength = 0
'--------------------------------------------------
' get the maximum value of the 'numbers' passed in
' --------------------------------------------------
for each number in tempnumarray
' Response.Write "
* " & number
If IsNumeric(number) Then
number = CDbl(number)
if number > max then max = number
end if
next
'Response.Write "
* max = " & max
' -------------------------
' calculate multiplier
' --------------------------
multiplier = maxheight/max
'Response.Write "
u bound array " & ubound(labelarray)
'Response.Write "
u bound array " & ubound(numarray)
'Response.Write "
max number is " & max
'Response.Write "
multiplier is " & multiplier
' ------------------------
' populate array
' ------------------------
For counter = 0 to ubound(tempnumarray)
Redim Preserve heightarray(counter)
If tempnumarray(counter) = max Then
heightarray(counter) = maxheight
Else
heightarray(counter) = tempnumarray(counter) * multiplier
End If
Next
tablestring = tablestring & "" & vbcrlf & _
"" & _
title & " " & vbcrlf & _
"" & vbCrLf
'loop through values
for counter = 0 to ubound(tempnumarray)
tablestring = tablestring & vbTab & ""
If addValues Then
tableString = tableString & ZeroFormat(tempnumarray(counter)) & ""
Else
tableString = tableString & "
"
End if
tableString = tableString & "
" & _
"'
'if color present use that color for bars
' tablestring = tablestring & color
' end if
barHeight = round(heightarray(counter),2)
' netscape doesn't recognize sizes less than 1
If barHeight < 2.00 Then barHeight = 2.00
If Trim(linkTo) = "" Then
tablestring = tablestring & "' height='" & barHeight & "'>" & _
"
" & _
"
"
Else
tablestring = tablestring & "' height='" & barHeight & "'>
" & _
"
"
End If
' -----------------------------
' put the values above the bar
' -----------------------------
'if addvalues then
' print actual values
' tablestring = tablestring & "
" & tempnumarray(counter)
'end if
tablestring = tablestring & " " & vbCrLf
next
tablestring = tablestring & " " & vbCrLf
' -------------------------------
' calculate the max length of labels
' -------------------------------
For Each label in labelarray
If len(label) >= maxlength then maxlength = len(label)
Next
' ---------------------------------------
' print labels and set each to maxlength
' ---------------------------------------
For Each label in labelarray
tablestring = tablestring & vbTab & "" & ""
For count = 0 to Round((maxlength - len(label))/2)
tablestring = tablestring & " "
next
if maxlength mod 2 <> 0 then tablestring = tablestring & " "
tablestring = tablestring & label
for count = 0 to round((maxlength - len(label))/2)
tablestring = tablestring & " "
next
tablestring = tablestring & " " & vbCrLf
Next
tablestring = tablestring & "
" & vbCrLf
tablestring = tablestring & "" & vbCrLf
makechart = tablestring
else
tablestring = tablestring & "" & vbcrlf & _
"" & _
title & " " & vbcrlf & _
" " & vbCrLf
makechart = tablestring & "" & " No
Data: " & _
" "
' "Error in Data:
' maxwidth and maxlength have to be greater then 0 ..... OR
' number of labels not equal to number of values ..... OR
' numbers aren't all blanks .... (eg new user)
Response.Write "
maxheight= " & maxheight
Response.Write "
maxwidth= " & maxwidth
Response.Write "
" & ubound(labelarray)
Response.Write "
" & ubound(numarray)
end if
end function
%>
<%
strTitle = "Bar Chart Title"
numStr = "1,2,3,4,5,6,7,8,9,8,7,6,5,4,3,2,1"
labelStr = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q"
numArray = Split(numStr,",")
labelArray = Split(labelStr,",")
strColour = "#abcdef"
strBGColour = "#ffffff"
intOutLineBorder = 1
strbarBorder = "yellow"
intMaxHeight = 400
intMaxWidth = 25
bAddValues = false
strLinkTo = "http://www.geocities.com/paulrowland2000/Dev/pageToLinkTo.html"
Response.Write makechart(strTitle,numArray,labelArray,strColour,strBGColour,intOutLineBorder,strbarBorder,intMaxHeight,intMaxWidth,bAddValues,strLinkTo)
%>