Create | statistics | A general function and its use case are given below, please refer to. <%
REM First we design a showcart function in which
REM Avalues is an array of values
REM Alables is the marking of the horizontal axis
REM Strtitle is the title of this statistic chart
REM strxaxislable X-axis label
REM stryaxislable Y-axis label
Sub Showchart (ByRef avalues, ByRef alabels, ByRef strtitle, ByRef Strxaxislabel, ByRef Stryaxislabel)
' You can arbitrarily change the graphic constants
' Unit is the pixel point of the screen
Const graph_width = 450 ' graphic width
Const graph_height = 250 ' graphics
Const Graph_border = 5 ' coordinate line width
The distance between the Const Graph_spacer = 2 ' statistic bar
Const Table_border = 0
' Variable declaration
Dim I
Dim Imaxvalue
Dim Ibarwidth
Dim Ibarheight
' Get avalues Maximum value
Imaxvalue = 0
For I = 0 to UBound (avalues)
If Imaxvalue < Avalues (i) Then imaxvalue = avalues (i)
Next ' I
' Calculate the width of each graphic
Ibarwidth = (Graph_width (UBound (avalues) + 1))-Graph_spacer
' Start drawing
%>
<table border= ' <%= table_border%> ' cellspacing= ' 0 ' cellpadding= ' 0 ' >
<TR>
<TD colspan= ' 3 ' align= ' center ' ></TR>
<TR>
<TD valign= ' center ' ><b><%= Stryaxislabel%></b></td>
<TD valign= ' top ' >
<table border= ' <%= table_border%> ' cellspacing= ' 0 ' cellpadding= ' 0 ' >
<TR>
& nbsp; &n BSP; <TD rowspan= ' 2 ' > ' ></TD>
<TD valign= ' top ' align= ' right ' ><%= imaxvalue%> </TD>
& nbsp; </TR>
<TR>
<TD valign= ' bottom ' align= ' right ' >0 </TD>
</TR>
</TABLE>
</TD>
<TD>
<table border= ' <%= table_border%> ' cellspacing= ' 0 ' cellpadding= ' 0 ' >
<TR>
<TD valign= ' bottom ' > ' height= ' <%= graph_height '%> ' ></TD>
<%
' Circle all the values in the array, draw the bar!
& nbsp; For I = 0 to UBound (avalues)
Ibarheight = Int ((avalues (I)/imaxvalue) * graph_height)
& nbsp; &n BSP; ' Because the browser ignores the 0-height bar graph, so use 1 instead!
& nbsp; If ibarheight = 0 Then ibarheight = 1
%>
<TD valign= ' bottom ' > ' height= ' 1 ' ></TD>
<TD valign= ' bottom ' > ' height= ' <%= ibarheight%> ' alt= ' <%= avalues (I)%> ' ></A></TD>
<%
& nbsp; Next ' I
%>
</TR>
<TR>
<TD colspan= ' <%= (2 * (UBound (avalues) + 1)) + 1%> ' > ' height= ' &L t;%= graph_border%> ' ></TD>
</TR>
<% ' Check whether the horizontal axis array is valid! %>
<% If IsArray (alabels) Then%>
<TR>
<TD><!--leave some space--></td>
<% for I = 0 to UBound (avalues)%>
<TD><!--leave some space--></td>
<TD align= ' center ' ><font size= ' 1 ' ><%= alabels (I)%></font></td>
<% Next ' I%>
</TR>
<% End If%>
</TABLE>
</TD>
</TR>
<TR>
<TD colspan= ' 2 ' ><!--to center the next TD element--></td>
<TD align= ' center ' ><br><b><%= Strxaxislabel%></b></td>
</TR>
</TABLE>
<%
End Sub
%>
<%
' A bar chart with a horizontal axis
Showchart Array (6, 10, 12, 18, 23, 26, 27, 28, 30, 34, 37, 45, 55), _
Array ("P1", "P2", "P3", "P4", "P5", "P6", "P7", "P8", "P9", _
"P10", "P11", "P12", "P13"), "Sales for several consecutive months", "X", "Y axis"
' Blank line
Response.Write "<BR>" & VbCrLf
Response.Write "<BR>" & VbCrLf
Response.Write "<BR>" & VbCrLf
' Construct an array of random numbers
Dim I
Dim Atemp (49)
Randomize
For I = 0 to 49
Atemp (I) = Int ((+ 1) * Rnd)
Next ' I
' Bar graph generated by random array
Showchart atemp, "This is not an array!", "Random bar graph", "Serial number", "Random number"
%>