11 Ağustos 2007 Cumartesi

How to Create Bar Charts

<%
Sub ShowChart(ByRef aValues, ByRef aLabels, ByRef strTitle, ByRef strXAxisLabel, ByRef strYAxisLabel)
Const gr_WIDTH = 450
Const gr_HEIGHT = 250
Const gr_BORDER = 5
Const gr_SPACER = 2
Const tbl_BORDER = 0
iMaxValue = 0
For I = 0 To UBound(aValues)
If iMaxValue < aValues(I) Then iMaxValue = aValues(I)
Next
iBarWidth = (gr_WIDTH \ (UBound(aValues) + 1)) - gr_SPACER
'NOTE: Each of the images you see in this code are just 1 pixel by 1 pixel
'wide, but we make them in different colors for the chart, and then
'stretch them to the size that we need them with the code below:
Response.Write"<table border="&tbl_BORDER&" cellspacing=0 cellpadding=0>"&_
"<tr><td colspan=3 align=center><h2>"&strTitle&"</h2></td></tr>"&_
"<tr>"&_
"<td valign=center><b>"&strYAxisLabel&"</td>"&_
"<td valign=top>"&_
"<table border="&tbl_BORDER&" cellspacing=0 cellpadding=0>"&_
"<tr>"&_
"<td rowspan=2><img src=""images/spacer.gif"" border=0 width=1 height="&gr_HEIGHT&"></td>"&_
"<td valign=top align=right>"&iMaxValue&" </td>"&_
"</tr>"&_
"<tr><td valign=bottom align=right>. </td></tr>"&_
"</table>"&_
"</td>"&_
"<td>"&_
"<table border="&tbl_BORDER&" cellspacing=0 cellpadding=0>"&_
"<tr>"&_
"<td valign=bottom><img src=""images/spacer_black.gif"" border=0 width="&gr_BORDER&" height="&gr_HEIGHT&"></td>"
For I = 0 To UBound(aValues)
iBarHeight = Int((aValues(I) / iMaxValue) * gr_HEIGHT)
If iBarHeight = 0 Then iBarHeight = 1
Response.Write"<td valign=bottom><img src=""images/spacer.gif"" border=0 width="&gr_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
Response.Write"</tr>"&_
"<tr><td colspan="&(2*(UBound(aValues)+1))+1&"><img src=""images/spacer_black.gif"" border=0 width="&gr_BORDER+((UBound(aValues)+1)*(iBarWidth+gr_SPACER))&" height="&gr_BORDER&"></td></tr>"
If IsArray(aLabels) Then
Response.Write"<tr><td> </td>"
For I = 0 To UBound(aValues)
Response.Write"<td> </td><td align=center><font size=1>"&aLabels(I)&"</td>"
Next
Response.Write"</tr>"
End If
Response.Write"</table></td></tr><tr><td colspan=2> </td><td align=center><br><b>"&strXAxisLabel&"</td></tr></table>"
End Sub
%>
<html><body bgcolor=white>
<%
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><br><br>"
Randomize
For I = 0 To 49
aTemp(I) = Int((50+1)*Rnd)
Next
ShowChart aTemp, "Note that this ain't an Array!", "Chart of 50 Random Numbers", "Index", "Value"
%>
</body></html>


0 Comments: