Generating chart with ASP

Source: Internet
Author: User
Chart <script language= "VBScript" runat= "SERVER" >
function Makechart (title, Numarray, Labelarray, color, bgcolor, bordersize, MaxHeight, MaxWidth, Addvalues)
' Function Makechart version 3

' Jason Borovoy
' Title:chart title
' Numarray:an array of values for the chart
' Labelarray:an array of labels coresponding to the values must me present
' Color If null uses different colors for bars If NOT null all bars color you specify
' BgColor Background color.
' Bordersize:border size or 0 for no border.
' Maxheight:maximum height for chart not including labels
' Maxwidth:width of each column
' Addvalues:true or False depending if you want the actual values shown on the chart
' When your call the function Use:response.write Makechart (parameters)

' Actually returnstring would be a better name
Dim tablestring
' max value is maximum table value
Dim max
' maxlength Maximum length of labels
Dim maxlength
Dim Tempnumarray
Dim Templabelarray
Dim Heightarray
Dim Colorarray
' Value to Multiplie chart values from to get relitive size
Dim Multiplier
' If data valid
If MaxHeight > 0 and maxwidth > 0 and UBound (labelarray) = UBound (Numarray) Then
' Colorarray:color of each bars if more bars then colors loop through
' If you don ' t like me choices change them, add them, delete them.
Colorarray = Array ("Red", "blue", "yellow", "Navy", "orange", "purple", "green")
Templabelarray = Labelarray
Tempnumarray = Numarray
Heightarray = Array ()
Max = 0
maxlength = 0
tablestring = "<table bgcolor=" "& BgColor &" ' border= ' "& Bordersize &" ' > ' & _
"<tr><td><table border= ' 0 ' cellspacing= ' 1 ' cellpadding= ' 0 ' >" & vbCrLf
' Get maximum value
For each stuff in Tempnumarray
If stuff > Max then max = Stuff End If
Next
' Calculate multiplier
Multiplier = Maxheight/max
' Populate array
For counter = 0 To UBound (tempnumarray)
If Tempnumarray (counter) = Max Then
ReDim Preserve Heightarray (counter)
Heightarray (counter) = MaxHeight
Else
ReDim Preserve Heightarray (counter)
Heightarray (counter) = Tempnumarray (counter) * Multiplier
End If
Next


' Set title
tablestring = tablestring & "<tr><th colspan=" "& UBound (Tempnumarray) +1 &" ' > "& _
"<font face= ' Verdana, Arial, Helvetica ' size= ' 1 ' ><U>" & title & "</TH></TR>" & _
VbCrLf & "<TR>" & VbCrLf
' Loop through values
For counter = 0 To UBound (tempnumarray)
tablestring = tablestring & VbTab & "<td valign= ' bottom ' align= ' center ' >" & _
"<font face= ' Verdana, Arial, Helvetica ' size= ' 1 ' >" & _
"<table border= ' 0 ' cellpadding= ' 0 ' width= '" & MaxWidth & "' ><tr>" & _
"<tr><td valign= ' bottom ' bgcolor= '"
If not isNUll (color) Then
' If color present use ' This color for bars
tablestring = tablestring & Color
Else
' If not loop through Colorarray
tablestring = tablestring & Colorarray (Counter mod (UBound (Colorarray) +1))
End If
tablestring = tablestring & "' height= '" & _
Round (Heightarray (counter), 2) & "' > "& _
"</td></tr></table>"
If Addvalues Then
' Print actual values
tablestring = tablestring & "<BR>" & Tempnumarray (Coun



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.