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
' 开始绘图
%
<TABLE BORDER='<%= TABLE_BORDER %' CELLSPACING='0' CELLPADDING='0'
<TR
<TD COLSPAN='3' ALIGN='center'<H2<%= strTitle %<TR
<TD VALIGN='center'<B<%= strYAxisLabel %<TD VALIGN='top'
<TABLE BORDER='<%= TABLE_BORDER %' CELLSPACING='0' CELLPADDING='0'
<TR
& nbsp; &n bsp; <TD ROWSPAN='2'<IMG src="http://img.tulaoshi.com/attachment/portal/jcwcj/2005-12/10/0512100053428287.gif" BORDER='0' WIDTH='1' HEIGHT='<%= GRAPH_HEIGHT %'<TD VALIGN='top' ALIGN='right'<%= iMaxValue % & nbsp; <TR
<TD VALIGN='bottom' ALIGN='right'0 <TD
<TABLE BORDER='<%= TABLE_BORDER %' CELLSPACING='0' CELLPADDING='0'
<TR
<TD VALIGN='bottom'<IMG src="http://img.tulaoshi.com/attachment/portal/jcwcj/2005-12/10/05121000534222251.gif" BORDER='0' WIDTH='<%= GRAPH_BORDER %' HEIGHT='<%= GRAPH_HEIGHT %'<%
' 对数组所有数值进行循环,绘制条形图!
& nbsp; For I = 0 To UBound(aValues)
iBarHeight = Int((aValues(I) / iMaxValue) * GRAPH_HEIGHT)
& nbsp; &n bsp; ' 因为浏览器会忽略0高度的条形图,所以用1代替!
& nbsp; If iBarHeight = 0 Then iBarHeight = 1
%
<TD VALIGN='bottom'<IMG src="http://img.tulaoshi.com/attachment/portal/jcwcj/2005-12/10/0512100053428287.gif" BORDER='0' WIDTH='<%= GRAPH_SPACER %' HEIGHT='1'<TD VALIGN='bottom'<IMG src="http://img.tulaoshi.com/attachment/portal/jcwcj/2005-12/10/05121000534240625.gif" BORDER='0' WIDTH='<%= iBarWidth %' HEIGHT='<%= iBarHeight %' ALT='<%= aValues(I) %'&