Here's an example script to chart a two-dimensional array. This script is helpful as it does not require images or a database. All data is derived from an array and preset colors. There are multiple values allowed for each dimension and these can be of any limit.
|
|
<%@ LANGUAGE="VBSCRIPT" %> <% Response.Buffer=true Response.AddHeader "cache-control", "private" Response.AddHeader "pragma", "no-cache" Response.ExpiresAbsolute = #January 1, 1990 00:00:01# Response.Expires=Now()-1 Response.AddHeader "Cache-Control", "must-revalidate" Response.AddHeader "Cache-Control", "no-cache" %>
<HTML> <HEAD> <META NAME="GENERATOR" Content="Visual N++"> <TITLE>Paging Through a Recordset</TITLE> </HEAD> <BODY bgColor=White text=Black>
<%
|
|
'------------------------------------------------------------------- 'For this article the array is set up manually 'It could also be passed to the page '-------------------------------------------------------------------
|
|
dim Arr(4,3) Arr(0,1)="Budget" Arr(0,2)="Actual" Arr(1,0)="1st Qtr" Arr(2,0)="2nd Qtr" Arr(3,0)="3rd Qtr" Arr(4,0)="4th Qtr"
|
|
'------------------------------------------------------------------- 'This is just to generate some sample values '-------------------------------------------------------------------
|
|
randomize
for x=1 to Ubound(Arr,1) for y = 1 to Ubound(Arr,2) Arr(x,y)=int(rnd*30)+1 next next
call chart(Arr,400,200)
sub chart(Arr,width,height)
|
|
'------------------------------------------------------------------- 'Set the dimension of the color array equal to number of 'parameters for the y axis 'then define a color for each parameter '-------------------------------------------------------------------
|
|
redim col(2) col(1)="red" col(2)="blue"
|
|
'------------------------------------------------------------------- 'Get the limits of the array dimensions '-------------------------------------------------------------------
|
|
y=ubound(Arr,2) x=ubound(Arr,1)
|
|
'------------------------------------------------------------------- 'calulate the total number of rows required for ouput 'this will be used to generate table dimensions later '-------------------------------------------------------------------
|
'------------------------------------------------------------------- 'Get the maximum value to be plotted in the x dimension '-------------------------------------------------------------------
|
|
hi=0 for i=1 to x for j=1 to y if cint(Arr(i,j))>hi then hi=cint(Arr(i,j)) next next
|
|
'------------------------------------------------------------------- 'Apportion the dimensions of the plot to fit the requested chart size '-------------------------------------------------------------------
|
|
coeffy=hi/height dimx=(width-(x*y)-1)/(x*(y+1))
|
|
'------------------------------------------------------------------- 'Finally, let's generate the chart! first set up a table '-------------------------------------------------------------------
|
|
response.write("<table cellpadding='0' cellspacing='0' border = 4 bordercolor='black'><TD>") & vbcrlf
|
|
'------------------------------------------------------------------- 'Generate the legend '-------------------------------------------------------------------
|
|
response.write("<tr><td colspan='3'>") & vbcrlf for i=1 to y-1 response.write( "<TR><TD><hr align = 'center' color = " & col(i) &_ " size ='10' width='10'></td>" & _ "<td colspan= '2' nowrap><font face='arial' size='2'>" & _ Arr(0,i) & "</TD></TR>") & vbcrlf next response.write("</td></tr>") & vbcrlf
|
|
'------------------------------------------------------------------- 'Generate the parameters of the y axis and values to be plotted '-------------------------------------------------------------------
|
|
for i=1 to x
response.write("<td rowspan='2'>") response.write("<font face=""arial"" size=""2"">" & Arr(i,0)) response.Write("</td>") & vbcrlf
|
|
'------------------------------------------------------------------- 'set up some temporary values to which we can assign the selected 'colors. these will be used by subroutine. 'This will need to be done manually -- continue sequence to 'match number of parameters '-------------------------------------------------------------------
|
|
colt1=col(1) colt2=col(2)
response.write("<tr><TD>") & vbcrlf for j = 1 to y-1
response.write( "<table CELLPADDING='0' CELLSPACING='0' LEFTMARGIN=0 TOPMARGIN='0' >")& vbcrlf response.write( "<TR><TD><hr align = 'left' color = " & colt1 & " size =" & dimx & _ " width=" & cdbl(Arr(i,j))/coeffy & "></TD><TD> " & int(cdbl(Arr(i,j))) & _ "</TD></TR>" ) & vbcrlf response.write( "</table>") & vbcrlf
|
|
'------------------------------------------------------------------- 'Rotate the color to next in sequence 'This will need to be set manually -- continue sequence to match 'the number of parameters '-------------------------------------------------------------------
|
|
temp=colt1 colt1=colt2 colt2=temp
next response.write("</TD></tr>") & vbcrlf
next
|
|
'------------------------------------------------------------------- 'Generate footer for the chart '-------------------------------------------------------------------
|
|
response.write ("<td align ='right'>0</td ><td align ='center'>" & _ " <I>Dollars in thousands </I></td>") response.write ("</table>")
end sub
%> |
(From: dotnet)
|