欢迎光临
我们一直在努力

用ASP制作饼图、柱状图等-ASP教程,ASP应用

建站超值云服务器,限时71元/月

我们工作中经常需要将数据转化成柱状图,饼图等,以方便直观的分析数据, 这里给大家介绍一个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 %>

<%
  response.expires = 0
  response.buffer = true
  response.clear 
  response.contenttype = “image/gif”

  set chart = server.createobject(“csdrawgraphtrial.draw”)

  chart.adddata “no> 1”, 17, “ff0000”
  chart.adddata “no> 2”, 28, “00ff00”
  chart.adddata “no> 3”, 5, “0000ff”

  if request.querystring(“type”) = “pie” then
    chart.title = “sample pie chart”
    chart.bgcolor = “eeeeee”
    chart.labelbgcolor = “eeeeee”
    chart.titlebgcolor = “eeeeee”
    response.binarywrite chart.gifpie
  else
    chart.title = “sample bar chart”
    response.binarywrite chart.gifbar
  end if

  response.end
%>

程序很简单,再些不详细说明,下面看一个将数据库中的数据转换到图表的例子:

lines.asp:

 <html>
<head>
<title>line graph showing all the results</title>

</head>

<body>
<table align=center width=400>
  <tr><td colspan=4><img src=”gif_lines.asp”  width=400 height=300></td></tr>
</table>
<p>links to the other result pages:</p>
<p><a href=barsbyday.asp>bar chart showing all results for any one day</a>.</p>
<p><a href=barsbycolour.asp>bar charts showing results for each colour separately</a>.</p>
</body>
</html>

gif_lines.asp:

 <%@ language=vbscript %>
<%
  利用数据库中的数据生成线图。
  根据4个不同的值分别生成4条线。
  在x轴上显示星期的名称。

  response.expires = 0
  response.buffer = true
  response.clear

  利用下面的语句创建chart对象,版本不同会有所差异。
  set chart = server.createobject(“csdrawgraph.draw”)
  set chart = server.createobject(“csdrawgraphtrial.draw”)

  connectionstring = “provider=microsoft.jet.oledb.4.0;data source=” & _
    server.mappath(“data.mdb”)
  set dbconn = server.createobject(“adodb.connection”)
  dbconn.open connectionstring
  set rs = server.createobject(“adodb.recordset”)
  sql = “select * from table1 order by day”
  rs.open sql, dbconn

    while not rs.eof
      chart.addpoint cint(rs(“day”)), cint(rs(“red”)), “ff0000”, “red”
      chart.addpoint cint(rs(“day”)), cint(rs(“blue”)), “0000ff”, “blue”
      chart.addpoint cint(rs(“day”)), cint(rs(“green”)), “00ff00”, “green”
      chart.addpoint cint(rs(“day”)), cint(rs(“yellow”)), “ffff00”, “yellow”
      chart.addxvalue cint(rs(“day”)), rs(“dayname”)
      rs.movenext
    wend

  关闭数据库连接
  rs.close
  dbconn.close

  下面设置组件属性
  x轴坐标从1开始而不是0。(xoffset = 1)

  chart.title = “all the combined results”
  chart.titlex = 100
  chart.yaxistext = “total for each day”
  chart.originy = 220
  chart.xoffset = 1
  chart.xtop = 7
  chart.xgrad = 1
  chart.usexaxislabels = true
  chart.linewidth = 2
  chart.pointsize = 3
  chart.pointstyle = 1

  最后图片以gif格式发送到浏览器
  response.contenttype = “image/gif”
  response.binarywrite chart.gifline
  response.end
%>

结果如图所示:

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 用ASP制作饼图、柱状图等-ASP教程,ASP应用
分享到: 更多 (0)

相关推荐

  • 暂无文章