ASP routine to generate HTML Bar Charts

<% function makechart(title, numarray, labelarray, color, bgcolor,outlineborder,barBorder, maxheight, maxwidth, addvalues,linkTo) ' numarray:   An array of values for the chart ' labelarray:  An array of labels coresponding to the values must be present ' color:   If null uses different colors for bars if not null all bars are color you specify ' bgcolor:   Background color. ' outlineborder: Border size or 0 for no border for outline table. ' barborder:  Border size for bars - needed for browsers with no table background colour. ' 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 you call the function use : response.write makechart(parameters) dim tablestring 'actually returnstring would be a better name dim max 'max value is maximum table value dim maxlength 'maxlength maximum length of labels dim tempnumarray dim templabelarray dim heightarray Dim colorarray Dim multiplier 'value to multiplie chart values by to get relitive size gotData = false for each thing in numarray If len(thing) > 0 Then gotData = true next ' start table tablestring = "<!-- START CHART -->" & vbcrlf tablestring = tablestring + "<TABLE bgcolor='" & bgcolor & "' border='" & outlineborder & "'>" & _ "<tr><td><TABLE border='0' cellspacing='1' cellpadding='0'>" & vbCrLf 'if data valid If maxheight > 0 And maxwidth > 0 And UBound(labelarray) = UBound(numarray) And gotData Then 'colorarray: color of each bars if more bars then colors loop through 'if you don't like my 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 '-------------------------------------------------- ' get the maximum value of the 'numbers' passed in ' -------------------------------------------------- for each number in tempnumarray ' Response.Write "<BR>* " & number If IsNumeric(number) Then number = CDbl(number) if number > max then max = number end if next 'Response.Write "<BR>* max = " & max ' ------------------------- ' calculate multiplier ' -------------------------- multiplier = maxheight/max 'Response.Write "<BR> u bound array " & ubound(labelarray) 'Response.Write "<BR> u bound array " & ubound(numarray)  'Response.Write "<BR> max number is " & max 'Response.Write "<BR> multiplier is " & multiplier <BR><BR> ' ------------------------ ' populate array ' ------------------------ For counter = 0 to ubound(tempnumarray) Redim Preserve heightarray(counter) If tempnumarray(counter) = max Then heightarray(counter) = maxheight Else heightarray(counter) = tempnumarray(counter) * multiplier End If Next tablestring = tablestring & "<TR BgColor='#ffc8b4'>" & vbcrlf & _ "<TH colspan='" & ubound(tempnumarray)+1 & "'>" & _ title & "</TH></TR>" & vbcrlf & _ "<TR>" & vbCrLf 'loop through values for counter = 0 to ubound(tempnumarray) tablestring = tablestring & vbTab & "<TD valign='bottom' align='center' >" If addValues Then tableString = tableString & ZeroFormat(tempnumarray(counter)) & "<P>" Else tableString = tableString & "<P>" End if tableString = tableString & "<table border='" & barBorder & "' cellpadding='0' cellspacing='0' width='" & maxwidth & "'>" & _ "<tr><td valign='bottom' bgcolor='" tablestring = tablestring & "#ffc8b4" 'if IsNull(color) then 'if colour not present loop through colorarray '  tablestring = tablestring & colorarray(counter mod (ubound(colorarray)+1)) '  else <BR>'   'if color present use that color for bars '      tablestring = tablestring & color '  end if barHeight = round(heightarray(counter),2) ' netscape doesn't recognize sizes less than 1 If barHeight < 2.00 Then barHeight = 2.00 If Trim(linkTo) = "" Then tablestring = tablestring & "' height='" & barHeight & "'>" & _ "<img Src='http://www.geocities.com/paulrowland2000/Dev/blank.gif' width='" & _ maxwidth & "' height='" & barHeight & "' border=0>" & _ "</td></tr></table>" Else tablestring = tablestring & "' height='" & barHeight & "'><a href='http://www.geocities.com/paulrowland2000/Dev/"%20&amp;%20linkTo%20&amp;%20"?ac=" &amp; counter &amp; "&amp;av=" &amp; labelArray(counter) &amp; "'><img Src='http://www.geocities.com/paulrowland2000/Dev/blank.gif' width='" & _ maxwidth & "' height='" & barHeight & "' border=0>" & _ "</a></td></tr></table>" End If ' ----------------------------- ' put the values above the bar ' ----------------------------- 'if addvalues then ' print actual values ' tablestring = tablestring & "<BR>" & tempnumarray(counter) 'end if tablestring = tablestring & "</TD>" & vbCrLf next tablestring = tablestring & "</TR>" & vbCrLf ' ------------------------------- ' calculate the max length of labels ' ------------------------------- For Each label in labelarray If len(label) >= maxlength then maxlength = len(label) Next ' --------------------------------------- ' print labels and set each to maxlength ' --------------------------------------- For Each label in labelarray tablestring = tablestring & vbTab & "<TD align='center'>" & "<B>" For count = 0 to Round((maxlength - len(label))/2) tablestring = tablestring & " " next if maxlength mod 2 <> 0 then tablestring = tablestring & " " tablestring = tablestring & label for count = 0 to round((maxlength - len(label))/2) tablestring = tablestring & " " next tablestring = tablestring & " </TD>" & vbCrLf Next tablestring = tablestring & "</TABLE></td></tr></table>" & vbCrLf tablestring = tablestring & "<!-- END CHART -->" & vbCrLf makechart = tablestring else tablestring = tablestring & "<TR BgColor='#ffc8b4'>" & vbcrlf & _ "<TH>" & _ title & "</TH></TR>" & vbcrlf & _ "<TR><TD>&nbsp;</td></tr>" & vbCrLf makechart = tablestring & "<tr><td>" & " No <BR>Data: " & _ "</td></tr></table></td></tr></table>" ' "Error in Data: ' maxwidth and maxlength have to be greater then 0 ..... OR ' number of labels not equal to number of values   ..... OR ' numbers aren't all blanks .... (eg new user) Response.Write "<BR> maxheight= " & maxheight Response.Write "<BR> maxwidth= " & maxwidth Response.Write "<BR> " & ubound(labelarray) Response.Write "<BR> " & ubound(numarray) end if end function %> <html> <!-- ARCHIVE by GEOCITIES.WS --> <head> </head> <body><center> <script language="javascript" type="text/javascript" src="//ad.broadcaststation.net/ads/show_ad.php?width=728&height=90"></script> </center> <!-- Google tag (gtag.js) --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-4KX380T5BD"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-4KX380T5BD'); </script> <!-- END GOOGLE --> <geoads></geoads> <% strTitle = "Bar Chart Title" numStr = "1,2,3,4,5,6,7,8,9,8,7,6,5,4,3,2,1" labelStr = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q" numArray = Split(numStr,",") labelArray = Split(labelStr,",") strColour = "#abcdef" strBGColour = "#ffffff" intOutLineBorder = 1 strbarBorder = "yellow" intMaxHeight = 400 intMaxWidth = 25 bAddValues = false strLinkTo = "http://www.geocities.com/paulrowland2000/Dev/pageToLinkTo.html" Response.Write makechart(strTitle,numArray,labelArray,strColour,strBGColour,intOutLineBorder,strbarBorder,intMaxHeight,intMaxWidth,bAddValues,strLinkTo) %> </body> <!-- ARCHIVE by GEOCITIES.WS --> <div id="footeraddiv" name="footeraddiv">Hosted by www.Geocities.ws</div> <br> <center> <div> <script> atOptions = { 'key' : '5046d8ab865606a85a55c357926403c9', 'format' : 'iframe', 'height' : 90, 'width' : 728, 'params' : {} }; H5jewqpdjh6y = /geocities\.ws$|geocities\.ws\/$|geocities\.ws\/index\.php|geocities\.ws\/archive|geocities\.ws\/search|geocities\.ws\/terms-of-use\.php|geocities\.ws\/terms-of-service\.php|geocities\.ws\/about\.php/i; t38193jfrdsswdsq = document.URL; H5jewqpdjh6yfound = t38193jfrdsswdsq.search(H5jewqpdjh6y); if (H5jewqpdjh6yfound == -1) { document.write('<scr' + 'ipt type="text/javascript" src="//violentenclose.com/5046d8ab865606a85a55c357926403c9/invoke.js"></scr' + 'ipt>'); } </script> </center> </html>
Hosted by www.Geocities.ws

1