我们工作中经常需要将数据转化成柱状图,饼图等,以方便直观的分析数据, 这里给大家介绍一个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")
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 ‘’关闭数据库连接 ‘’下面设置组件属性 ‘’最后图片以GIF格式发送到浏览器 |
结果如图所示: