用ASP制做餅圖、柱狀圖等
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
[p] 我們工作中經(jīng)常需要將數(shù)據(jù)轉(zhuǎn)化成柱狀圖,餅圖等,以方便直觀的分析數(shù)據(jù), 這里給大家介紹一個(gè)asp中制作餅圖、柱狀圖的組件:csdrawgraph,csdgt.zip,因?yàn)槭墙M件,所以我們?cè)谑褂弥靶枰胷egsvr32.exe 注冊(cè)一下,csdrawgraph,可以在asp中創(chuàng)建餅圖,柱狀圖以及線圖,其支持的格式有g(shù)if, 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]程序很簡(jiǎn)單,再些不詳細(xì)說(shuō)明,下面看一個(gè)將[url=http://ninedns.com/webhosting/mssql.asp]數(shù)據(jù)庫(kù)[/url]中的數(shù)據(jù)轉(zhuǎn)換到圖表的例子: [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]數(shù)據(jù)庫(kù)[/url]中的數(shù)據(jù)生成線圖。[br]'根據(jù)4個(gè)不同的值分別生成4條線。[br]'在x軸上顯示星期的名稱。[/p] [p]response.expires = 0[br]response.buffer = true[br]response.clear[/p] [p] '利用下面的語(yǔ)句創(chuàng)建chart對(duì)象,版本不同會(huì)有所差異。[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]'關(guān)閉[url=http://ninedns.com/webhosting/mssql.asp]數(shù)據(jù)庫(kù)[/url]連接[br]rs.close[br]dbconn.close[/p] [p]'下面設(shè)置組件屬性[br]'x軸坐標(biāo)從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格式發(fā)送到瀏覽器[br]response.contenttype = "image/gif"[br]response.binarywrite chart.gifline[br]response.end[br]%>[/p] [p]結(jié)果如圖所示:[/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 編輯過(guò) |
相關(guān)文章
正在查詢... |