用ASP制做饼图、柱状图等
当前位置:点晴教程→知识管理交流
→『 技术文档交流 』
[p] 我们工作中经常需要将数据转化成柱状图,饼图等,以方便直观的分析数据, 这里给大家介绍一个asp中制作饼图、柱状图的组件:csdrawgraph,csdgt.zip,因为是组件,所以我们在使用之前需要用regsvr32.exe 注册一下,csdrawgraph,可以在asp中创建饼图,柱状图以及线图,其支持的格式有gif, png, jpg and bmp.[/p]
[p] 看看如下的柱状图,饼图如何生成的例子:[/p]
[p][align=center][img]http://ninedns.com/images/tech/images/a4215_img200748_1.jpg[/img][/align][/p]
[p][br]chartdemo.asp[/p]
<%@ language=vbscript %>[br][br][br]
this simple demonstration shows two graphs using the same data. the first is [br]a bar chart: [br][br] [br]the second is a pie chart. the background colour is set to light [br]grey to show the overall size of the image. [br][br] [br][br] [p]chartimages.asp[/p] [p]<%@ language=vbscript %>[/p] [p]<%[br]response.expires = 0[br]response.buffer = true[br]response.clear [br]response.contenttype = "image/gif"[/p] [p]set chart = server.createobject("csdrawgraphtrial.draw")[/p] [p][br]chart.adddata "no> 1", 17, "ff0000"[br]chart.adddata "no> 2", 28, "00ff00"[br]chart.adddata "no> 3", 5, "0000ff"[/p] [p]if request.querystring("type") = "pie" then[br] chart.title = "sample pie chart"[br] chart.bgcolor = "eeeeee"[br] chart.labelbgcolor = "eeeeee"[br] chart.titlebgcolor = "eeeeee"[br] response.binarywrite chart.gifpie[br]else[br] chart.title = "sample bar chart"[br] response.binarywrite chart.gifbar[br]end if[/p] [p]response.end[br]%>[/p][br]程序很简单,再些不详细说明,下面看一个将[url=http://ninedns.com/webhosting/mssql.asp]数据库[/url]中的数据转换到图表的例子: [p][/p] [p]lines.asp:[/p] [p][br][br]links to the other result pages: [br]bar chart showing all results for any one day. [br]bar charts showing results for each colour separately. [br][br][/p] [p]gif_lines.asp:[/p] [p]<%@ language=vbscript %>[br]<%[br]'利用[url=http://ninedns.com/webhosting/mssql.asp]数据库[/url]中的数据生成线图。[br]'根据4个不同的值分别生成4条线。[br]'在x轴上显示星期的名称。[/p] [p]response.expires = 0[br]response.buffer = true[br]response.clear[/p] [p] '利用下面的语句创建chart对象,版本不同会有所差异。[br]'set chart = server.createobject("csdrawgraph.draw")[br]set chart = server.createobject("csdrawgraphtrial.draw")[/p] [p]connectionstring = "provider=microsoft.jet.oledb.4.0;data source=" & _ [br] server.mappath("data.mdb")[br]set dbconn = server.createobject("adodb.connection")[br]dbconn.open connectionstring[br]set rs = server.createobject("adodb.recordset")[br]sql = "select * from table1 order by day"[br]rs.open sql, dbconn[/p] [p] while not rs.eof[br] chart.addpoint cint(rs("day")), cint(rs("red")), "ff0000", "red"[br] chart.addpoint cint(rs("day")), cint(rs("blue")), "0000ff", "blue"[br] chart.addpoint cint(rs("day")), cint(rs("green")), "00ff00", "green"[br] chart.addpoint cint(rs("day")), cint(rs("yellow")), "ffff00", "yellow"[br] chart.addxvalue cint(rs("day")), rs("dayname")[br] rs.movenext[br] wend[/p] [p]'关闭[url=http://ninedns.com/webhosting/mssql.asp]数据库[/url]连接[br]rs.close[br]dbconn.close[/p] [p]'下面设置组件属性[br]'x轴坐标从1开始而不是0。(xoffset = 1)[br][br]chart.title = "all the combined results"[br]chart.titlex = 100[br]chart.yaxistext = "total for each day"[br]chart.originy = 220[br]chart.xoffset = 1[br]chart.xtop = 7[br]chart.xgrad = 1[br]chart.usexaxislabels = true[br]chart.linewidth = 2[br]chart.pointsize = 3[br]chart.pointstyle = 1[/p] [p]'最后图片以gif格式发送到浏览器[br]response.contenttype = "image/gif"[br]response.binarywrite chart.gifline[br]response.end[br]%>[/p] [p]结果如图所示:[/p] [p][align=center][img]http://ninedns.com/images/tech/images/a4215_img200748_2.gif[/img][/align][/p] [p]csdrawgraph的下载地址:http://chestysoft.com/download/csdgt.zip[/p]该文章在 2010/7/3 14:23:21 编辑过 |
相关文章
正在查询... |