WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

HTML

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Sample Code to Generate HTML Barchart

Keywords:   html barchart

The script is quick and clean - enjoy
; Winbatch - Create HTML file which displays data as a
;            bar chart. Very simple example used.
;
; Stan Littlefield - December 17, 2002

cOUT   = StrCat( dirget(),"BARCHART.HTM" )
If FileExist( cOUT ) Then FileDelete( cOUT )
BoxOpen("Winbatch Bar Chart Generator",cOUT )

; build an array of Barchart Names,amounts and colors
; You would probably want to read in tabular data, or XML
nRows  = 5 ; 1 less than array elements
names  = "UK,France,Germany,USA,Poland,Iceland"
nums   = "11,5,7,12,16,9"
cols   = "Blue,Red,Black,Pink,Green,Yellow"

aNames = Arrayize( names,"," )
aNums  = Arrayize( nums,"," )
aCols  = Arrayize( cols,"," )

; start writing HTML header
s      = ""
s      = StrCat(s,"<html>",@CRLF)
s      = StrCat(s,"",@CRLF)
s      = StrCat(s,"<head>",@CRLF)
s      = StrCat(s,'<meta http-equiv="Content-Type"',@CRLF)
s      = StrCat(s,'content="text/html; charset=iso-8859-1">',@CRLF)
s      = StrCat(s,"<title>My Barchart Data</title>",@CRLF)
s      = StrCat(s,"</head>",@CRLF)
s      = StrCat(s,"",@CRLF)
s      = StrCat(s,"<body>",@CRLF)

; Process the Array
highest = 0
counter = 0
s       = StrCat(s, "<div align=center><center><table border=0 bordercolor=#C0C0C0><tr>",@CRLF)

For i   = 0 To nRows
   s    = StrCat(s,"<td>",aNames[counter],"</td>",@CRLF)
   If aNums[counter] > highest Then highest = aNums[counter]
   For j = 0 To ( aNums[counter] -1 )
      s  = StrCat( s,"<td bgcolor=" ,aCols[counter], "> ",@CRLF )
   Next
   s     = StrCat( s, "</td>" )
   counter = counter+1
   s     = StrCat( s, "</tr>",@CRLF )

Next
s        = StrCat( s, "<tr>" )
s        = StrCat( s, "<td>Total</td>",@CRLF )
newcounter = 1

For i = 1 To highest
   If newcounter <10
      s = StrCat( s, "<td bgcolor=#C0C0C0><strong><center> ",newcounter,"</td>",@CRLF )
   Else
      s = StrCat( s, "<td bgcolor=#C0C0C0><strong><center>",newcounter,"</td>",@CRLF )
   Endif
   newcounter = newcounter+1
Next

; conclude the HTML
s = StrCat(s,"</body>",@CRLF)
s = StrCat(s,"</html>",@CRLF)

handle = FileOpen(cOUT,"WRITE")
FileWrite(handle,s)
FileClose(handle)

BoxShut()
Exit
; end of script

Article ID:   W15699
File Created: 2003:05:13:11:29:38
Last Updated: 2003:05:13:11:29:38