怎樣在ASP裡面建立統計圖表

來源:互聯網
上載者:User
建立|統計|圖表 下面給出了一個通用的函數及其用例,請參考。 <%
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 %></H2></TD>
</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'><IMG SRC='http://www.163design.net/a/y/images/spacer.gif' BORDER='0' WIDTH='1' HEIGHT='<%= GRAPH_HEIGHT %>'></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'><IMG SRC='http://www.163design.net/a/y/images/spacer_black.gif' BORDER='0' WIDTH='<%= GRAPH_BORDER %>' HEIGHT='<%= GRAPH_HEIGHT %>'></TD>
<%
' 對數組所有數值進行迴圈,繪製橫條圖!
& 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://www.163design.net/a/y/images/spacer.gif' BORDER='0' WIDTH='<%= GRAPH_SPACER %>' HEIGHT='1'></TD>
<TD VALIGN='bottom'><IMG SRC='http://www.163design.net/a/y/images/spacer_red.gif' BORDER='0' WIDTH='<%= iBarWidth %>' HEIGHT='<%= iBarHeight %>' ALT='<%= aValues(I) %>'></A></TD>
<%
& nbsp; Next 'I
%>
</TR>
<TR>
<TD COLSPAN='<%= (2 * (UBound(aValues) + 1)) + 1 %>'><IMG SRC='http://www.163design.net/a/y/images/spacer_black.gif' BORDER='0' WIDTH='<%= GRAPH_BORDER + ((UBound(aValues) + 1) * (iBarWidth + GRAPH_SPACER)) %>' HEIGHT='<%= GRAPH_BORDER %>'></TD>
</TR>
<% ' 檢查橫座標數組是否有效! %>
<% If IsArray(aLabels) Then %>
<TR>
<TD><!-- 留點空間 --></TD>
<% For I = 0 To UBound(aValues) %>
<TD><!-- 留點空間 --></TD>
<TD ALIGN='center'><FONT SIZE='1'><%= aLabels(I) %></FONT></TD>
<% Next 'I %>
</TR>
<% End If %>
</TABLE>
</TD>
</TR>
<TR>
<TD COLSPAN='2'><!-- 使下一個TD元素置中--></TD>
<TD ALIGN='center'><BR><B><%= strXAxisLabel %></B></TD>
</TR>
</TABLE>
<%
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 "<BR>" & vbCrLf
Response.Write "<BR>" & vbCrLf
Response.Write "<BR>" & vbCrLf
' 構造一個由隨機數組成的數組
Dim I
Dim aTemp(49)
Randomize
For I = 0 to 49
aTemp(I) = Int((50 + 1) * Rnd)
Next 'I
' 由隨機數組產生的橫條圖
ShowChart aTemp, "這不是一個數組!", "隨機橫條圖", "序號 ", "隨機數"
%>



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.