<%
REM 首先我们
设计一个ShowCart函数,其中
REM aValues 是一个数值数组
REM aLables 是横坐标的标号
REM strTitle是这个统计图的标题
REM strXAxisLable X轴的标签
REM strYAxisLable Y轴的标签
Sub ShowChart(ByRef aValues, ByRef aLabels, ByRef strTitle, ByRef strXAxisLabel, ByRef strYAxisLabel)
" 你可以随便改变的图形常数
" 单位是屏幕
像素点
Const GRAPH_WIDTH = 450 " 图形宽度
Const GRAPH_HEIGHT = 250 " 图形
Const GRAPH_BORDER = 5 " 坐标线宽度
Const GRAPH_SPACER = 2 " 统计条之间的距离
Const TABLE_BORDER = 0
" 变量声明
Dim I
Dim iMaxValue
Dim iBarWidth
Dim iBarHeight
" 取得aValues最大值
iMaxValue = 0
For I = 0 To UBound(aValues)
If iMaxValue < aValues(I) Then iMaxValue = aValues(I)
Next "I
" 计算每条图形的宽度
iBarWidth = (GRAPH_WIDTH \ (UBound(aValues) + 1)) - GRAPH_SPACER
" 开始绘图
%>
" CELLSPACING="0" CELLPADDING="0">
<%= strTitle %> |
<%= strYAxisLabel %> |
" CELLSPACING="0" CELLPADDING="0">
"> |
<%= iMaxValue %> |
0 |
|
" CELLSPACING="0" CELLPADDING="0">
" HEIGHT="<%= GRAPH_HEIGHT %>"> | <% " 对数组所有数值进行循环,绘制条形图! For I = 0 To UBound(aValues) iBarHeight = Int((aValues(I) / iMaxValue) * GRAPH_HEIGHT) " 因为浏览器会忽略0高度的条形图,所以用1代替! If iBarHeight = 0 Then iBarHeight = 1 %>
" HEIGHT="1"> |
" HEIGHT="<%= iBarHeight %>" ALT="<%= aValues(I) %>"> | <% Next "I %>
">" HEIGHT="<%= GRAPH_BORDER %>"> |
<% " 检查横坐标数组是否有效! %> <% If IsArray(aLabels) Then %>
| <% For I = 0 To UBound(aValues) %>
|
<%= aLabels(I) %> | <% Next "I %>
<% End If %>
|
|
<%= strXAxisLabel %> |
<%
End Sub
%>
<%
" 一个带有横坐标的条形图
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"), "连续几个月的销售额", "X 轴", "Y 轴"
" 空行
Response.Write "
" & vbCrLf
Response.Write "
" & vbCrLf
Response.Write "
" & vbCrLf
" 构造一个由随机数组成的数组
Dim I
Dim aTemp(49)
Randomize
For I = 0 to 49
aTemp(I) = Int((50 + 1) * Rnd)
Next "I
" 由随机数组生成的条形图
ShowChart aTemp, "这不是一个数组!", "随机条形图", "序号", "随机数"
%>