上一篇:用ASP生成Chart (二维饼图) >>
用ASP生成Chart
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 you 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 by 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 dont 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
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 that 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) & "><img src=chart.gif width=1 height=1>" & _
"</td></tr></table>"
if addvalues then
print actual values
tablestring = tablestring & "<br>" & tempnumarray(counter)
end if
tablestring = tablestring & "</td>" & vbcrlf
next
tablestring = tablestring & "</tr>" & vbcrlf
calculate max lenght of labels
for each stuff in labelarray
if len(stuff) >= maxlength then maxlength = len(stuff)
next
print labels and set each to maxlength
for each stuff in labelarray
tablestring = tablestring & vbtab & "<td align=center><" & _
"font face=verdana, arial, helvetica size=1><b> "
for count = 0 to round((maxlength - len(stuff))/2)
tablestring = tablestring & " "
next
if maxlength mod 2 <> 0 then tablestring = tablestring & " "
tablestring = tablestring & stuff
for count = 0 to round((maxlength - len(stuff))/2)
tablestring = tablestring & " "
next
tablestring = tablestring & " </td>" & vbcrlf
next
tablestring = tablestring & "</table></td></tr></table>" & vbcrlf
makechart = tablestring
else
response.write "error function makechart: maxwidth and maxlength have to be greater " & _
" then 0 or number of labels not equal to number of values"
end if
end function
dim stuff
dim labelstuff
demo 1
stuff = array(5,30)
labelstuff = array("北京", "广州")
response.write makechart("demo 1", stuff, labelstuff, null, "gold",10, 50,40,true)
</script>
()
下一篇:使用ASP建立Http组件 >>
相关文章:
- · ASP Chart 简要介绍
- · Jmail的属性和方法
- · W3 Jmail 参考说明
- · W3 Jmail 使用范例
- · w3 upload组件实例应用2
- · w3 upload组件实例应用1
- · rs.open sql,conn,1,1 的后两个 1,1 各代表什么?
- · 如何编程实现修改数据库 login Id 的口令
- · Top 和 Distinct 的 区别
- · 在select语句中使用top的一些小技巧
- · 利用SQL语言有没有办法查到表中哪些记录中的全部(或某些字段)的值相同?
- · 如何编程实现备份数据库
- · 如何在sql server系统表中获得用户表的修改时间
- · Select INTO 语句出错,如何解决?
- · 如何 编程实现 备份数据库
- · 我需要多大马力?(自MS)--IIS的配置需求
- · ADO如何新增修改删除数据库的记录呢?
- · 如何调试用VC写的服务器端控件?
- · 服务器端组件的最小需求是什么?我能够使用已经存在的Automation servers吗
- · 能不能在ASP中实现对服务器上执行本地程序,比如执行一个可执行文件
- · ASP.NET 中的随机密码生成
- · J2EE 开发购物网站 经验篇 - 建表
- · 实战 J2EE 开发购物网站 - 创建数据库
- · 实战 J2EE 开发购物网站 二
- · 实战 J2EE 开发购物网站 经验篇
- · 认识和优化 connection 对象
- · 浅谈 ASP 程序的编程与优化
- · 优化Web数据库页面
- · 怎样才能将query string从一个asp文件传送到另一个?
- · 为何我在asp程序内使用msgbox,程序出错说没有权限
- · 如何传递变量从一页到另一页
- · 强迫输入密码对话框
- · 如何链结到一副图片上
- · 如何确定对方的IP地址
- · 如何回到先前的页面
- · 如何显示随机图象
- · 如何计算每天的平均反复访问人数
- · 我如何知道使用者所用的浏览器?
