How to create a statistical chart in ASP

Source: Internet
Author: User
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>
&LT;TD colspan= ' 3 ' align= ' center ' ></TR>
<TR>
&LT;TD valign= ' center ' ><b><%= Stryaxislabel%></b></td>
&LT;TD valign= ' top ' >
<table border= ' <%= table_border%> ' cellspacing= ' 0 ' cellpadding= ' 0 ' >
<TR>
& nbsp; &n BSP; &LT;TD rowspan= ' 2 ' > ' ></TD>
&LT;TD valign= ' top ' align= ' right ' ><%= imaxvalue%> </TD>
& nbsp; </TR>
<TR>
&LT;TD valign= ' bottom ' align= ' right ' >0 </TD>
</TR>
</TABLE>
</TD>
<TD>
<table border= ' <%= table_border%> ' cellspacing= ' 0 ' cellpadding= ' 0 ' >
<TR>
&LT;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
%>
&LT;TD valign= ' bottom ' > ' height= ' 1 ' ></TD>
&LT;TD valign= ' bottom ' > ' height= ' <%= ibarheight%> ' alt= ' <%= avalues (I)%> ' ></A></TD>
<%
& nbsp; Next ' I
%>
</TR>
<TR>
&LT;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>
&LT;TD align= ' center ' ><font size= ' 1 ' ><%= alabels (I)%></font></td>
<% Next ' I%>
</TR>
<% End If%>
</TABLE>
</TD>
</TR>
<TR>
&LT;TD colspan= ' 2 ' ><!--to center the next TD element--></td>
&LT;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"
%>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.