<%
Option Explicit
'std variables
Dim MAXHEIGHT, BARWIDTH
Dim DATAMIN, DATAMAX, DATASCALE
Dim data(20), i
'some variables for interpolated graphs
Dim num_interp, tval, j
'Make some fake data, normally ou would get this from a db or other data storage
Randomize()
For i = 0 to UBound(data)
data(i) = Rnd() * 1000
Next
'backto the real code, find the min/max for data
DATAMIN = data(0)
DATAMAX = data(0)
For i = 1 to UBound(data)
if data(i) < DATAMIN Then DATAMIN = data(i)
if data(i) > DATAMAX Then DATAMAX = data(i)
Next
'Now define the height we want the graph to be and width of the bars
MAXHEIGHT = 200
'Now find a scaled height for the data
' we could use the DATAMIN for the min if we didn't know the theoretical data range,
' in this case I will use 0 for a better looking graph
DATASCALE = MAXHEIGHT/DATAMAX
'----------------------------
' Now we output our table and graph as a bar graph
BARWIDTH = 5
Response.Write "Bar Graph"
Response.Write "<table cellpadding=""0"" cellspacing=""0"" style=""border:1px solid #336699""><tr>"
For i = 0 to UBound(data)
MakeBar cInt(DATASCALE * data(i)), BARWIDTH, True, True, "blue"
Next
response.Write "</tr></table>"
'----------------------------
' Now we output the graph as a dotted graph
BARWIDTH = 2
Response.Write "<hr><br>Dotted Graph"
Response.Write "<table cellpadding=""0"" cellspacing=""0"" style=""border:1px solid #336699""><tr>"
For i = 0 to UBound(data)
MakeBar cInt(DATASCALE * data(i)), BARWIDTH, False, True, "blue"
Next
Response.Write "</tr></table>"
'----------------------------
' Now we output the dotted graph using interpolated data
num_interp = 4 '3 interpolated columns, 1 real column
BARWIDTH = 2
Response.Write "<hr><br>Interpolated Dotted Graph"
Response.Write "<table cellpadding=""0"" cellspacing=""0"" style=""border:1px solid #336699""><tr>"
'output the first bar as a starting place
MakeBar cInt(DATASCALE * data(0)), BARWIDTH, False, True, "blue"
'output the rest by outputting 3 interpolated bars and then the actual data bar
For i = 1 to UBound(data)
For j = 1 to num_interp
tval = cInt( ( data(i-1) * (num_interp-j)/num_interp ) + ( data(i) * j/num_interp ) )
MakeBar cInt(DATASCALE * tval), BARWIDTH, False, True, "blue"
Next
Next
Response.Write "</tr></table>"
'----------------------------
' Heavily Interpolated Dotted Graph
num_interp = 20 '3 interpolated columns, 1 real column
BARWIDTH = 2
Response.Write "<hr><br>Heavily Interpolated Dotted Graph"
Response.Write "<table cellpadding=""0"" cellspacing=""0"" style=""border:1px solid #336699""><tr>"
'output the first bar as a starting place
MakeBar cInt(DATASCALE * data(0)), BARWIDTH, False, False, "blue"
'output the rest by outputting 3 interpolated bars and then the actual data bar
For i = 1 to UBound(data)
For j = 1 to num_interp
tval = cInt( ( data(i-1) * (num_interp-j)/num_interp ) + ( data(i) * j/num_interp ) )
MakeBar cInt(DATASCALE * tval), BARWIDTH, False, False, "blue"
Next
Next
Response.Write "</tr></table>"
'----------------------------
' pseudo-solid graph, works better if the vertical changes are as sudden
num_interp = 4
BARWIDTH = 3
Response.Write "<hr><br>Interpolated Solid Graph"
Response.Write "<table cellpadding=""0"" cellspacing=""0"" style=""border:1px solid #336699""><tr>"
'output the first bar as a starting place
MakeBar cInt(DATASCALE * data(0)), BARWIDTH, False, False, "blue"
'output the rest by outputting 3 interpolated bars and then the actual data bar
For i = 1 to UBound(data)
For j = 1 to num_interp
tval = cInt( ( data(i-1) * (num_interp-j)/num_interp ) + ( data(i) * j/num_interp ) )
MakeBar cInt(DATASCALE * tval), BARWIDTH, True, False, "blue"
Next
Next
Response.Write "</tr></table>"
'----------------------------
' pseudo-solid graph,heavy interpolation
BARWIDTH = 1
num_interp = 20
Response.Write "<hr><br>Heavily Interpolated Pseudo-Dotted-Line Graph"
Response.Write "<table cellpadding=""0"" cellspacing=""0"" style=""border:1px solid #336699""><tr>"
'output the first bar as a starting place
MakeBar cInt(DATASCALE * data(0)), BARWIDTH, True, False, "blue"
'output the rest by outputting x interpolated bars with the last one being the actual data
For i = 1 to UBound(data)
For j = 1 to num_interp
tval = cInt( ( data(i-1) * (num_interp-j)/num_interp ) + ( data(i) * j/num_interp ) )
MakeBar cInt(DATASCALE * tval), BARWIDTH, True, False, "blue"
Next
Next
Response.Write "</tr></table>"
'-------------------------
' Sub to output bars
Sub MakeBar(scaled_data_val, bar_width, is_solid, is_spaced,color)
Response.Write "<td style=""width:" & bar_width & "px;"" valign=""bottom"">"
Response.Write "<div style=""width:" & bar_width & "px;height:" & scaled_data_val & "px;"
If is_solid Then
Response.Write "background-color:" & color & ";"
Else
Response.Write "border-top:" & bar_width & "px solid " & color & ";"
End If
Response.Write """></div></td>"
If is_spaced Then
Response.Write "<td style=""width:" & bar_width & "px;""> </td>"
End If
End Sub
%>