利用office web component打造精品图表(一) 选择自 online 的 Blog
2005-02-06 22:44
423 查看
大家在编写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
strChartFile = ExportChartToGIF(objChartSpace, strChartAbsPath, strChartRelPath)
Response.Write "<IMG SRC=""" & strChartFile & """>" & "<P>"
CleanUpGIF strChartAbsPath
objRS.Close
set objRS = nothing
set objConn = nothing
set objSeries = nothing
set objChart = nothing
set objChartSpace = nothing
%>
</div>
</BODY>
</HTML>
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
strChartFile = ExportChartToGIF(objChartSpace, strChartAbsPath, strChartRelPath)
Response.Write "<IMG SRC=""" & strChartFile & """>" & "<P>"
CleanUpGIF strChartAbsPath
objRS.Close
set objRS = nothing
set objConn = nothing
set objSeries = nothing
set objChart = nothing
set objChartSpace = nothing
%>
</div>
</BODY>
</HTML>
相关文章推荐
- 利用office web component打造精品图表(二) 选择自 online 的 Blog
- 利用office web component打造精品图表(一)
- 利用office web component打造精品图表(二)
- 利用office web component打造精品图表
- 利用office web component打造精品图表(二)
- 利用office web component打造精品图表(一)
- 1分钟创建图表[利用Office Web Component OWC组件]
- 如何用owc(office web component)画图表
- 在 Asp.Net Web 应用程序中长时间装载页面时显示进度条 选择自 chenweionline 的 Blog
- web下水晶报表的使用! 选择自 Jeacey 的 Blog
- 利用树型结构进行排序 选择自 0210 的 Blog
- 基于MVC+EasyUI的Web开发框架经验总结(1)-利用jQuery Tags Input 插件显示选择记录
- 利用CAsyncSocket类实现Socket编程 选择自 yuguanglou 的 Blog
- 利用Highcharts制作web图表学习(一)
- 体验SharePoint Online Office Web App
- Ultrawebgrid中利用JS将选择行移到第一条,下一条,上一条,最末条
- Microsoft.Office.Interop.Excel的用法以及利用Microsoft.Office.Interop.Excel将web页面转成PDF
- 利用python2.7打造1个web站点2
- Office 2013 Web App Server + SharePoint 2013 Integration(Techtalk写的PPT丢掉了,所以赶紧将blog补上)
- 利用Sublimetext3&virtualenv 打造一个Web&Python IDE