设为首页   加入最爱           最新更新:全方位英文文章资料库
 
资料坊搜索: 标题 全文     
ASP中使用Office2000中的图表控件
   首页>>YesizeCOM>>电脑技能坊>>ASP>>正文       
 
广告招租,e-mail:yesize@hotmail.com

广告招租,e-mail:yesize@hotmail.com


-- Microsoft Office Chart 9.0 制作图表

前一阵为了做图表,查看了论坛中的所有文章,但大都是用Aspchart,ShortGraph等组件,这些组件多半都是国外开发要money的。如果你用office 的MS Chart,往往作出的效果又差强人意。如果你使用过Office2000中Excel的图表的话,应该被一流的效果所折服。想把他搬上你的网站吗?没问题,现在你也能通过ASP和VBScript来实现Microsoft Office Chart 9.0 的强大的功能和绝妙的效果。

示例中使用 ADO 记录集中的数据创建图表。首先根据返回的记录集数据创建以制表符分隔的字符串,然后通过 SetData 方法并使用此字符串设置图表数据。

源文件chart.asp :

(参照微软帮助范例,加入部分本人的修改...)

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft FrontPage 4.0">
</HEAD>
<BODY>
<object id=ChartSpace1 classid=CLSID:0002E500-0000-0000-C000-000000000046 style="width:80%;height:350"></object>
<object id=ADOConnection1 classid=CLSID:00000514-0000-0010-8000-00AA006D2EA4></object>

<script Language=VBScript>

Sub Window_OnLoad()
Dim rs, categories, values

categories = ""
values = ""

打开连接执行sql查询 (建立“nwind.mdb”库,并创建名为“Category Sales for 1995”的表)
ADOConnection1.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\nwind.mdb"
Set rs = ADOConnection1.Execute("SELECT * FROM [Category Sales for 1995]")

对于每一字段记录产生一个由制表符分隔的字符串
rs.MoveFirst
Do while Not rs.EOF
categories = categories & rs.Fields(0).Value & Chr(9)
values = values & rs.Fields(1).Value & Chr(9)
rs.MoveNext
Loop
rs.Close
ADOConnection1.Close

删去字符串末尾的分隔符
categories = Left(categories, Len(categories) - 1)
values = Left(values, Len(values) - 1)

创建一个系列
ChartSpace1.Clear
ChartSpace1.Charts.Add
ChartSpace1.Charts(0).SeriesCollection.Add
ChartSpace1.Charts(0).SeriesCollection(0).Caption = "Sales"

使用recordset生成的字符串设置系列的类型和值
Set c = ChartSpace1.Constants
ChartSpace1.Charts(0).SeriesCollection(0).SetData c.chDimCategories, c.chDataLiteral, categories
ChartSpace1.Charts(0).SeriesCollection(0).SetData c.chDimValues, c.chDataLiteral, values

设置图表工作区的标题,并将图表工作区的图例放置于工作区的右边。
ChartSpace1.HasChartSpaceTitle = True
With ChartSpace1.ChartSpaceTitle
.Caption = "Monthly Sales Data"
.Font.Size = 12
.Font.Color = "#FF0000"
.Font.Bold = True
End with

ChartSpace1.HasChartSpaceLegend = True
With ChartSpace1.ChartSpaceLegend
.Position = c.chLegendPositionright
.Font.Color = "#009999"
.Font.Size = 9
End with

设置图表类型(具体样式见附录)
ChartSpace1.Charts(0).Type = c.chChartTypeBarClustered
轴的坐标格式、样式(有坐标轴时才设)
With ChartSpace1.Charts(0).Axes(c.chAxisPositionBottom)
.NumberFormat = "#,##0"
.Font.Size = 9
End with

With ChartSpace1.Charts(0).Axes(c.chAxisPositionLeft)
.Font.Color = "#0000ff"
.Font.Size = 9
End with
end if

End Sub
</script>
</BODY>
</HTML>

以上程序在Win98+PWS 下通过。

通过以上的例程你可以根据你的需要,增加自己所需要的效果,一定能制作出极酷的统计图表来的,需要帮助可以参见微软的帮助文件(装了 Office2000 就有)Msowcvba.chm 以及MSDN 在线帮助。

有个缺点:客户端好像也要装Office2000 才行,另外我还没找到如何不安装 Office2000 来注册该组件的方法,如果那位高手知道,请告诉我 luo_zhenyu@netease.com ,谢谢!

附:

ChartChartTypeEnum Constants 图表类型常数(转至MSDN)

Constant Value

chChartTypeCombo -1
chChartTypeColumnClustered 0
chChartTypeColumnStacked 1
chChartTypeColumnStacked100 2
chChartTypeBarClustered 3
chChartTypeBarStacked 4
chChartTypeBarStacked100 5
chChartTypeLine 6
chChartTypeLineMarkers 7
chChartTypeLineStacked 8
chChartTypeLineStackedMarkers 9
chChartTypeLineStacked100 10
chChartTypeLineStacked100Markers 11
chChartTypeSmoothLine 12
chChartTypeSmoothLineMarkers 13
chChartTypeSmoothLineStacked 14
chChartTypeSmoothLineStackedMarkers 15
chChartTypeSmoothLineStacked100 16
chChartTypeSmoothLineStacked100Markers 17
chChartTypePie 18
chChartTypePieExploded 19
chChartTypePieStacked 20
chChartTypeScatterMarkers 21
chChartTypeScatterSmoothLineMarkers 22
chChartTypeScatterSmoothLine 23
chChartTypeScatterLineMarkers 24
chChartTypeScatterLine 25
chChartTypeScatterLineFilled 26
chChartTypeBubble 27
chChartTypeBubbleLine 28
chChartTypeArea 29
chChartTypeAreaStacked 30
chChartTypeAreaStacked100 31
chChartTypeDoughnut 32
chChartTypeDoughnutExploded 33
chChartTypeRadarLine 34
chChartTypeRadarLineMarkers 35
chChartTypeRadarLineFilled 36
chChartTypeRadarSmoothLine 37
chChartTypeRadarSmoothLineMarkers 38
chChartTypeStockHLC 39
chChartTypeStockOHLC 40
chChartTypePolarMarkers 41
chChartTypePolarLine 42
chChartTypePolarLineMarkers 43
chChartTypePolarSmoothLine 44
chChartTypePolarSmoothLineMarkers 45


上一篇:解决在执行数据库查询中的特殊字符的问题 下一篇:用几行Asp代码实现防止表单多次被提交

版权说明:作品来源于网上,版权归作者所有,如果无意中侵犯了您的版权,请来信告知,本站将在3个工作日内删除。yesize@hotmail.com
  热门小游戏分类 
射击小游戏 连连看小游戏
台球小游戏 成人小游戏
CS小游戏 化妆小游戏
赛车小游戏 休闲小游戏
篮球小游戏 换装小游戏
儿童小游戏 牛牛小游戏
麻将小游戏 冒险小游戏
美媚小游戏 益智小游戏
体育小游戏  
Society Recreation & Sports
Travel & Leisure Communications
Vehicles Computers
Fashion Arts & Entertainment
Reference & Education Disease & Illness
Writing & Speaking Politics
Product Reviews Food & Beverage
Finance Internet Business
Self Improvement Home & Family
Health & Fitness Business
最新更新内容
警惕“公务员报考热”背
公务员考试不是丈母娘考
一名新公务员的自白:我
公务员考脑筋急转弯与挂
北努斗:2006行政能力测
大讨论:06行测BT题目大
过来人回忆:当年,我也
一家之言:公务员热折射
公务员考试申论要是有正
数十万大学生走进公务员
      粤ICP备05005424         Copyright ©2000 - 2004 Yesize.COM