应用OWC11(office 2003)编写了一个动态生成统计图表的测试用例,出错,请高手检查!!
Asp+sql 2000,出错问题在代码中,高手指点下啊!
<!--include file = "adovbs.inc "-->
<!--adovbs文件中是一些用Recordset打开数据库时的常量-->
<%@ Language=VBScript %>
<%
Option Explicit
'Response.Expires=-1
'Response.ContentType= "image/gif "
'页面级对象
Dim m_cn '连接对象
dim m_rs '纪录集对象
dim m_cspace 'OWC.ChartSpace
Dim m_objBinaruFile '二进制文件流对象
dim m_sYear '需要查询的年份
dim sSQL
dim c 'OWC常量对象
dim cht '图表
dim ax '数轴
dim fnt '字体
dim sFullFileName '输出GIF文件的临时参考路径
dim ConnString
'获得查询年份,缺省为2007
m_sYear=Request( "year ")
if len(m_sYear)=0 then m_sYear= "2007 "
set m_cn=server.CreateObject( "ADODB.Connection ")
set m_rs=server.CreateObject( "ADODB.Recordset ")
ConnString = "Provider=SQLOLEDB;Data Source=HU;UID=sa; PWD=123;Database=sale " '连接SQl数据库Data Source 数据库服务器名 Database=数据库名
m_cn.Open ConnString
'数据库sale中有一表Sales(三个字段,OrderDate,Salesperson,ExtendedPrice)
sSQL= "select Month([OrderDate]) AS [Month],Salesperson,Sum(ExtendedPrice) AS Sales from sales where OrderDate between '1/1/ " & m_sYear & " ' and '12/31/ " & m_sYear & " ' " & "Group by Month([OrderDate]),Salesperson "
'查询语句写在同一行,注意空格问题
m_rs.Open sSQL,m_cn,3,3
'图例
set m_cspace=server.CreateObject( "OWC11.ChartSpace ") '出错Server 对象, ASP 0177 (0x800401F3)无效的类别字符串
set cht=m_cspace.Charts.Add()
set c=m_cspace.Constants
cht.Type=c.chChartTypeLineMarkers '设置显示类型
cht.HasLegend=True
'设置数据源及图表属性
set m_cspace.DataSource=m_rs
cht.SetData c.chDimSeriesNames,0, "Salesperson " '序列名称
cht.SetData c.chDimCategories,0, "Month " '分类组
cht.SetDate c.chDimValues,0, "Sales " '取值
'增加一个图表标题
cht.HasTitle=True
cht.Title.Caption=m_sYear & "的销售金额 "
set fnt=cht.Title.Font
fnt.Name= "宋体 "
fnt.Size=10
fnt.Bold=True
'分类轴添加标题
set ax=cht.Axes(c.chAxisPositionBottom)
ax.HasTitle=True
set fnt=ax.Title.Font
fnt.Name= "宋体 "
fnt.Size=8
fnt.Bold=True
'数值轴添加标题
set ax=cht.Axes(c.chAxisPositionLeft)
ax.NumberFormat= "Currency "
ax.HasTitle=True
ax.Title.Caption= "元 "
set fnt=ax.Title.Font
fnt.Name= "宋体 "
fnt.Size=8
fnt.Bold=True
'用临时变量名保存当前文件,文件名唯一
set m_fso=CreateObject( "Scripting.FileSystemObject ")
sFullName=Server.MapPath( ". ") & "\ " & m_fso.GetTempName()
m_cspace.ExportPicture