欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

VbScript 封裝MS OWC(二)

程序员文章站 2022-04-10 08:04:45
复制代码 代码如下:''owc1.vbs class owc private o '傳入物件 public sub create(id_,width_,height_,lo...
复制代码 代码如下:

''owc1.vbs
class owc
private o
'傳入物件
public sub create(id_,width_,height_,location_)
set o = document.createelement("object")
o.setattribute "id",id_
o.setattribute "classid","clsid:0002e55d-0000-0000-c000-000000000046"
o.setattribute codebase="owc11.dll"
o.style.width=width_
o.style.height=height_
document.getelementbyid(location_).appendchild(o)
end sub
'畫圖矩形圖
'chart_bgcolor_圖表的背景顏色
'chartcaption_圖表的標題
'chartcaption_fontcolor_圖表標題顏色
'interior_color_矩形內的填充顏色
'caption_名稱
'categories_名稱數組
'values_值數組串
public sub bar(chart_bgcolor_,chartcaption_,chartcaption_fontcolor_,interior_color_,caption_,categories_,values_)
o.clear
set cht = o.charts.add
set c = o.constants
cht.type = c.chcharttypecolumnclustered
'設背景色或是填充
o.charts(0).plotarea.interior.setsolid chart_bgcolor_

'加上圖表的標題
o.haschartspacetitle = true
set cst=o.chartspacetitle
cst.caption = chartcaption_
cst.font.color = chartcaption_fontcolor_
cst.font.italic = false
cst.font.name = "arial"
cst.font.size = 12
cst.font.underline = c.owcunderlinestylesingle

'添加數據
cht.setdata c.chdimcategories, c.chdataliteral, categories_
cht.seriescollection(0).setdata c.chdimvalues, c.chdataliteral, values_
'直條的背景色進行設定
set sc=o.charts(0).seriescollection(0)
sc.interior.color=interior_color_

'直條上的顯示設置
sc.caption=caption_
set dl = cht.seriescollection(0).datalabelscollection.add
dl.hasvalue = true
dl.haspercentage = false
dl.font.size = 9
dl.font.color = "red"
dl.position = c.chlegendpositionright
dl.numberformat = "00.00%"
'左邊百分比的屬性設置
set cta = cht.axes(c.chaxispositionleft)
cta.font.size = 9
cta.numberformat = "0.0%"
cta.majorunit = 0.1
end sub
'多系列矩形圖
'chart_bgcolor_圖表的背景顏色
'chartcaption_圖表的標題
'chartcaption_fontcolor_圖表標題顏色
'color_顏色數組
'caption_名稱數組
'categories_名稱數組
'values_值數組
public sub serbar(chart_bgcolor_,chartcaption_,chartcaption_fontcolor_,color_,caption_,categories_,values_)
o.clear
o.charts.add
set c = o.constants
'圖表的類型
o.charts(0).type=c.chcharttypecolumnclustered
'給繪圖區加背景色
o.charts(0).plotarea.interior.setsolid chart_bgcolor_
''加上圖表的標題
o.haschartspacetitle = true
o.chartspacetitle.caption = chartcaption_
'標題的屬性
o.chartspacetitle.font.color = chartcaption_fontcolor_
o.chartspacetitle.font.italic = false
o.chartspacetitle.font.name = "arial"
o.chartspacetitle.font.size = 12
o.chartspacetitle.font.underline = c.owcunderlinestylesingle
'用循環來新增seriescollection以及里面的內容
for i=0 to ubound(caption_)
valuetemp=""
for j = i*(ubound(categories_)+1) to (i+1)*(ubound(categories_)+1)-1
valuetemp = valuetemp & "," & values_(j)
next
valuearr = split(mid(valuetemp,2),",")
o.charts(0).seriescollection.add
o.charts(0).seriescollection(i).caption = caption_(i)
o.charts(0).seriescollection(i).interior.color = color_(i)
o.charts(0).seriescollection(i).setdata c.chdimcategories, c.chdataliteral, categories_
o.charts(0).seriescollection(i).setdata c.chdimvalues, c.chdataliteral, valuearr
set dl = o.charts(0).seriescollection(i).datalabelscollection.add
dl.hasvalue = true
dl.haspercentage = false
dl.font.size = 9
dl.font.color = "red"
dl.position = c.chlegendpositionright
dl.numberformat = "00.00%"
next
''圖例的設定
o.charts(0).haslegend = true
o.charts(0).legend.font.size = 9
o.charts(0).legend.position = c.chlegendpositionbottom
''左邊百分比的屬性設置
set cta = o.charts(0).axes(c.chaxispositionleft)
cta.font.size = 9
cta.numberformat = "0.00%"
cta.majorunit = 0.1
end sub
'畫圓餅圖
'chart_bgcolor_繪圖區加背景色
'chartcaption_圖表的標題
'chartcaption_fontcolor_圖表標題顏色
public sub pie(chart_bgcolor_,chartcaption_,chartcaption_fontcolor_,caption_,categories_,values_)
o.clear
set cht = o.charts.add
set c = o.constants
cht.type = c.chcharttypepie3d
'給繪圖區加背景色
o.charts(0).plotarea.interior.setsolid chart_bgcolor_
cht.extrudeangle = 90
cht.chartdepth = 169
cht.aspectratio = 120
cht.rotation =180
cht.inclination=70

o.haschartspacetitle = true
o.chartspacetitle.caption = chartcaption_
o.chartspacetitle.font.color = chartcaption_fontcolor_
o.chartspacetitle.font.name = "arial"
o.chartspacetitle.font.size = 12
o.chartspacetitle.font.underline = c.owcunderlinestylesingle

cht.haslegend = true
cht.legend.font.size = 9
cht.legend.position = c.chlegendpositionbottom

cht.setdata c.chdimcategories, c.chdataliteral, categories_
cht.seriescollection(0).setdata c.chdimvalues, c.chdataliteral, values_
set sc=o.charts(0).seriescollection(0)
sc.caption=caption_
set dl = cht.seriescollection(0).datalabelscollection.add
dl.separator = ":"
dl.hasvalue = false
dl.hasseriesname = false
dl.hascategoryname=true
dl.haspercentage = true
dl.font.size = 9
dl.font.color = "red"
dl.numberformat = "00.00%"
end sub
'拆線圖
'chart_bgcolor_繪圖區加背景色
'chartcaption_圖表的標題
'chartcaption_fontcolor_圖表標題顏色
public sub line(chart_bgcolor_,chartcaption_,chartcaption_fontcolor_,caption_,categories_,values_)
o.clear
set cht = o.charts.add
set c = o.constants
cht.type = c.chcharttypelinemarkers
'給繪圖區加背景色
o.charts(0).plotarea.interior.setsolid chart_bgcolor_
o.haschartspacetitle = true
o.chartspacetitle.caption = chartcaption_
o.chartspacetitle.font.color = chartcaption_fontcolor_
o.chartspacetitle.font.name = "arial"
o.chartspacetitle.font.size = 12
o.chartspacetitle.font.underline = c.owcunderlinestylesingle

cht.setdata c.chdimcategories, c.chdataliteral, categories_
cht.seriescollection(0).setdata c.chdimvalues, c.chdataliteral, values_

set sc=o.charts(0).seriescollection(0)
sc.caption=caption_
set dl = cht.seriescollection(0).datalabelscollection.add
dl.hasvalue = true
dl.haspercentage = false
dl.font.size = 9
dl.font.color = "red"

set categoryaxis = cht.axes(c.chaxispositionbottom)
categoryaxis.font.size = 9

set categoryaxis = cht.axes(c.chaxispositionleft)
categoryaxis.font.size = 9
end sub
'多系列拆線圖
'chart_bgcolor_圖表的背景顏色
'chartcaption_圖表的標題
'chartcaption_fontcolor_圖表標題顏色
'color_顏色數組
'caption_名稱數組
'categories_名稱數組
'values_值數組
public sub serline(chart_bgcolor_,chartcaption_,chartcaption_fontcolor_,color_,seriesnames_,categories_,values_)
o.clear
set cht = o.charts.add
set c = o.constants
'設置圖表類型
cht.type = c.chcharttypelinemarkers
'給繪圖區加背景色
o.charts(0).plotarea.interior.color=chart_bgcolor_
'加上標題
o.haschartspacetitle = true
o.chartspacetitle.caption = chartcaption_
o.chartspacetitle.font.color = chartcaption_fontcolor_
o.chartspacetitle.font.name = "arial"
o.chartspacetitle.font.size = 12
''添加數據
cht.setdata c.chdimseriesnames, c.chdataliteral, seriesnames_
cht.setdata c.chdimcategories, c.chdataliteral, categories_

set categoryaxis = cht.axes(c.chaxispositionbottom)
categoryaxis.font.size = 9

set categoryaxis = cht.axes(c.chaxispositionleft)
categoryaxis.font.size = 9

for i = 0 to ubound(seriesnames_)
valuetemp = ""
for j = i*(ubound(categories_)+1) to (i+1)*(ubound(categories_)+1)-1
valuetemp = valuetemp & "," & values_(j)
next
valuearr = split(mid(valuetemp,2),",")
cht.seriescollection(i).setdata c.chdimvalues, c.chdataliteral, valuearr
cht.seriescollection(i).line.color = color_(i)
cht.seriescollection(i).line.weight = c.owclineweightthin
cht.seriescollection(i).marker.style = c.chmarkerstylediamond
cht.seriescollection(i).interior.color = color_(i)
set dl = cht.seriescollection(i).datalabelscollection.add
dl.hasvalue = true
dl.haspercentage = false
dl.font.size = 9
dl.font.color="red"
next
end sub
'清除圖型
public sub clear()
o.clear
end sub
end class
 
复制代码 代码如下:

<html>
<head>
<title>vbscript owc class test</title>
<script language="vbscript" src="owc1.vbs"></script>
<script language="vbscript">
sub window_onload()
set t = new owc

categories =array("a2-1","a2-2","a2-3","a3-1","a3-2","a3-3"_
,"b2-1","b2-2","b2-3","b3-1","b3-2","b3-3"_
,"c2-1","c2-2","c3-1","c3-2","c3-3")
values = array(0.813,0.689,0.800,0.833,0.681,0.864,0.743_
,0.894,0.822,0.874,0.746,0.908,0.850_
,0.728,0.731,0.734,0.624)
t.create "cs1","100%","400px","c1"
t.bar "#ffffff","報表標題","blue","#cccc00","組別",categories,values

color=array("#ccffff","#99ccff","#00ccff","#ff0000","#660066","#ff8080")
caption=array("第1周","第2周","第3周","第4周")
categories=array("a棟","b棟")
values=array(0.6951,0.5798,0.7075,0.512,0.7907,0.7493,0.8691,0.7716)
t.create "cs2","100%","400px","c2"
t.serbar "#ffffff","2008年10月坑頭三廠各周各樓層達成率比較圖","red",color,caption,categories,values

categories=array("臺北","上海")
values = array(238760,912560.62)
t.create "cs3","100%","400px","c3"
t.pie "#ffffff","銷售金額所佔比例(城市分類)","blue","城市",categories,values

categories =array("2008/11/1","2008/11/2","2008/11/3","2008/11/4","2008/11/5","2008/11/6","2008/11/7","2008/11/8","2008/11/9","2008/11/10","2008/11/11","2008/11/12","2008/11/13","2008/11/14","2008/11/15","2008/11/16","2008/11/17","2008/11/18","2008/11/19","2008/11/20","2008/11/21","2008/11/22","2008/11/23","2008/11/24","2008/11/25","2008/11/26","2008/11/27","2008/11/28","2008/11/29","2008/11/30")
values = array(67239.89,60400.26,7202.89,18453.12,28889.29,102136.25,78826.39,146291.6,93743.29,44204.44,45349.28,50730.6,37900.21,84359.87,169333.62,114594.96,75334.77,51360.32,55853.05,37912.63,45068.22,63930.98,72993.71,18699.5,24714.5,34792.91,39414.58,92171.2,74433.06,3998894.41)
t.create "cs4","100%","400px","c4"
t.line "#ffffff","銷售金額","blue","日期",categories,values

color=array("#ccffff","#99ccff","#00ccff","#ff0000")
seriesnames = array("a產品","b產品","c產品","d產品")
categories = array("2005/3/24","2005/3/25","2005/3/26","2005/3/27","2005/3/28")
values = array(50,100,20,80,89,40,60,20,90,70,20,50,55,25,60,80,20,75,58,100)
t.create "cs5","100%","400px","c5"
t.serline "#ffffff","達成率月報表","red",color,seriesnames,categories,values

set t=nothing
end sub
</script>
</head>
<body>
<div id="c1"></div>
<div id="c2"></div>
<div id="c3"></div>
<div id="c4"></div>
<div id="c5"></div>
</body>
</html>