我们工作中经常需要将数据转化成柱状图,饼图等,以方便直观的分析数据, 这里给大家介绍一个asp中制作饼图、柱状图的组件:csdrawgraph,csdgt.zip,因为是组件,所以我们在使用之前需要用regsvr32.exe 注册一下,csdrawgraph,可以在asp中创建饼图,柱状图以及线图,其支持的格式有gif, png, jpg and bmp.
看看如下的柱状图,饼图如何生成的例子:


chartdemo.asp
| <%@ language=vbscript %> <html> <head> <title>csdrawgraph demonstration</title> </head> <body bgcolor=”#ffffff”> <p>this simple demonstration shows two graphs using the same data. the first is a bar chart:</p> <p align=”center”><img src=”chartimages.asp?type=bar” width=”400″ height=”300″> </p> <p align=”left”>the second is a pie chart. the background colour is set to light grey to show the overall size of the image.</p> <p align=”center”><img src=”chartimages.asp?type=pie” width=”400″ height=”300″> </p> </body> </html> |
chartimages.asp
|
<%@ language=vbscript %> <% set chart = server.createobject(“csdrawgraphtrial.draw”) chart.adddata “no> 1”, 17, “ff0000” if request.querystring(“type”) = “pie” then response.end |
程序很简单,再些不详细说明,下面看一个将数据库中的数据转换到图表的例子:
lines.asp:
|
<html> </head> <body> |
gif_lines.asp:
|
<%@ language=vbscript %> response.expires = 0 利用下面的语句创建chart对象,版本不同会有所差异。 connectionstring = “provider=microsoft.jet.oledb.4.0;data source=” & _ while not rs.eof 关闭数据库连接 下面设置组件属性 chart.title = “all the combined results” 最后图片以gif格式发送到浏览器 |
结果如图所示:
