利用office web component打造精品图表(一)[1]

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 online 的 blog

大家在编写asp程序的时候,可能要对各种指标以图形的方式显示出来。如果仅仅是柱状图,可以采用画表格的方法。许多投票程序多采用这种方法。如果是饼状图或从数据库中检索数据后再显示,就有些困难了.办法也有,自己可以封装excel来完成上述功能,或者用deiphi做一个activeform传入参数,或者用php来写,java也可以。当然,用一个比较成熟的图形组件来完成更好一些。microsoft  office  web  compoent非常不错。我在开发一个项目的时候,用到了这个组件。

chart.asp程序。

<%  option  explicit  %>
<!--#include  file="adovbs.inc"-->
<html>
<head>
<title>柱状图的例子</title>
<%
function  exportcharttogif(objcspace,  strabsfilepath,  strrelfilepath)
dim  strfilename
randomize  
strfilename  =  timer  &  rnd  &  ".gif"
objcspace.exportpicture  strabsfilepath  &  "\"  &  strfilename,  "gif",  650,  400
exportcharttogif  =  strrelfilepath  &  "/"  &  strfilename
end  function

sub  cleanupgif(gifpath)
dim  objfs
dim  objfolder
dim  gif
set  objfs  =  server.createobject("scripting.filesystemobject")
set  objfolder  =  objfs.getfolder(gifpath)
for  each  gif  in  objfolder.files
if  instr(gif.name,  ".gif")  >  0  and  
datediff("n",  gif.datelastmodified,  now)  >  10  then
objfs.deletefile  gifpath  &  "\"  &  gif.name,  true
end  if
next
set  objfolder  =  nothing
set  objfs  =  nothing
end  sub

%>
</head>
<body  bgcolor="#ffffff">
<div  align="center">
<br>
<br>
<%
dim  sj1,sj2
sj1=request.querystring("s1")
sj2=request.querystring("s2")  

dim  objchartspace
dim  objchart
dim  objseries
dim  objconn
dim  objrs
dim  c
dim  series
dim  strchartabspath
dim  strchartrelpath
dim  strchartfile
dim  axis

strchartabspath  =  server.mappath("/xjsi-web/dcss/chart")
strchartrelpath  =  "/xjsi-web/dcss/chart"
'设置组件

set  objchartspace  =  server.createobject("owc.chart")
set  objchart  =  objchartspace.charts.add
set  c  =  objchartspace.constants

objchartspace.border.color="red"
'以柱状图显示
objchart.type=1
objchart.haslegend  =  true'是否显示图例
objchartspace.haschartspacetitle=true  '显示标题
objchartspace.chartspacetitle.caption  ="柱状图的例子使用office  web组件--www.ourfly.com中文技术网站"  
set  objconn  =  server.createobject("adodb.connection")
objconn.open  application("strconn")
set  objrs  =  server.createobject("adodb.recordset")
set  objrs.activeconnection  =  objconn
objrs.cursortype  =  adopenstatic
objrs.cursorlocation  =  aduseclient
objrs.open  "select  dwsj,sum(jfrs)  as  jfrs  
from  dcss_do_jfgcfxb  where  dwsj>='"&sj1&"'  and  dwsj<'"&sj2&"'  
group  by  dwsj  order  by  dwsj  asc"

set  objchartspace.datasource  =  objrs
'显示图例内容
objchart.setdata  c.chdimseriesnames,  0,  "jfrs"
for  each  objseries  in  objchart.seriescollection
objseries.setdata  c.chdimcategories,  0,  "dwsj"
objseries.setdata  c.chdimvalues,  0,  "jfrs"
next

for  each  axis  in  objchart.axes
axis.hastitle  =  true
if  axis.type  =  c.chcategoryaxis  then
axis.title.caption  =  "月份"
else
axis.title.caption  =  "人数"
end  if
next

本文关键:asp,office web component
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top