IV.Xây dựng ứng dụng BAR CHART

Một phần của tài liệu Giáo trình lập trình ứng dụng CSDL Web ASP pptx (Trang 132 - 136)

II. Xây dựng ứng dụng Directory List

IV.Xây dựng ứng dụng BAR CHART

Ta xây dựng ứng dụng này ðể mô tả cách xây dựng một bar chart ộbiểu ðồ cộtờ trong ASP. Tất nhiên có rất nhiều component giúp cho việc tạo các chartứ Sau khi duyệt biểu ðồ sản sinh ra có dạng nhý sau

Trýớc hết ta phải có ế tệp ỗỡỳ ðể vẽ ắẳĩRT ồ spacer.gif : dùng ngãn cách giữa các cộtứ

spacer_black.gif : dùng ðể cho việc vẽ hai trục ứ spacer_red.gif : dùng vẽ cột ộví dụ trên có màu ðỏờứ

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 iMaxValue = 0 For I = 0 To UBound(aValues)

If iMaxValue < aValues(I) Then iMaxValue = aValues(I) Next

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>

<TD ROWSPAN="2"><IMG SRC="./images/spacer.gif" BORDER="0" WIDTH="1" HEIGHT="<%= GRAPH_HEIGHT %>"></TD>

<TD VALIGN="top" ALIGN="right"><%= iMaxValue %>&nbsp;</TD> </TR>

<TD VALIGN="bottom" ALIGN="right">0&nbsp;</TD> </TR>

</TABLE> </TD> <TD>

<TABLE BORDER="<%= TABLE_BORDER %>" CELLSPACING="0" CELLPADDING="0">

<TR>

<TD VALIGN="bottom"><IMG SRC="./images/spacer_black.gif" BORDER="0" WIDTH="<%= GRAPH_BORDER %>" HEIGHT="<%= GRAPH_HEIGHT %>"></TD>

<%

For I = 0 To UBound(aValues)

iBarHeight = Int((aValues(I) / iMaxValue) * GRAPH_HEIGHT) If iBarHeight = 0 Then iBarHeight = 1

%>

<TD VALIGN="bottom"><IMG SRC="./images/spacer.gif"

BORDER="0" WIDTH="<%= GRAPH_SPACER %>" HEIGHT="1"></TD> <TD VALIGN="bottom"><IMG SRC="./images/spacer_red.gif"

BORDER="0" WIDTH="<%= iBarWidth %>" HEIGHT="<%= iBarHeight %>" ALT="<%= aValues(I) %>"></A></TD>

<% Next %> </TR> <TR>

<TD COLSPAN="<%= (2 * (UBound(aValues) + 1)) + 1 %>"><IMG SRC="./images/spacer_black.gif" BORDER="0" WIDTH="<%= (adsbygoogle = window.adsbygoogle || []).push({});

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 %> </TR> <% End If %> </TABLE> </TD> </TR> <TR> <TD COLSPAN="2"></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"), "Chart Title", "X Label", "Y Label"

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

ShowChart aTemp, "Note that this isn't an Array!", "Chart of 50 Random Numbers", "Index", "Value"

[ 263 ]

The process of uploading an image involves:

1. Verify if the file was uploaded (that is, verify that someone isn't trying to upload a file already on the server). This could be done using:

Một phần của tài liệu Giáo trình lập trình ứng dụng CSDL Web ASP pptx (Trang 132 - 136)