Тема: VBS: Пример построения диаграмм с помощью OWC
Доброго всем времени суток. Хочу привести пример построения диаграмм с помощью компонента ChartSpace из Office Web Components, поставляющегося в комплекте MS Office 2000 (OWC 9), 2003 (OWC 10) и XP (OWC 11). В данном случае используется библиотека %CommonProgramFiles%\microsoft shared\Web Components\11\OWC11.DLL
В окне браузера
option explicit
dim display, chartspace, xval, yarr
' create ie window for output
set display = new outputwindow
' create chart
set chartspace = display.document.createelement("object")
with chartspace
.id = "ChartSpace"
.setattribute "width", "100%"
.setattribute "height", "100%"
' OWC10.ChartSpace clsid:0002E546-0000-0000-C000-000000000046
' OWC11.ChartSpace clsid:0002E55D-0000-0000-C000-000000000046
.setattribute "classid", "clsid:0002E55D-0000-0000-C000-000000000046"
.clear
.refresh
end with
' fill and append chart
randomdata xval, yarr
display.body.appendchild fillchart(chartspace, xval, yarr)
do
wscript.sleep 100
loop
sub randomdata(xval, yarr)
' Create categories array and array of values arrays
dim catsqty, rowsqty, yval, i, j
randomize
catsqty = 4 + int(rnd * 6) ' categories qty in each row
rowsqty = int(sqr(rnd) * 4) ' rows qty
redim xval(catsqty)
for i = 0 to catsqty
xval(i) = "Cat" & i
next
redim yval(catsqty)
redim yarr(rowsqty)
for j = 0 to rowsqty
for i = 0 to catsqty
yval(i) = int(rnd * 1000)
next
yarr(j) = yval
next
end sub
function fillchart(chartspace, xval, yarr)
dim c, i
set c = chartspace.constants
with chartspace.charts.add
.type = c.chcharttypecolumnstacked3d
.hastitle = true
.title.caption = "Chart with " & (ubound(yarr) + 1) & " rows in " & (ubound(xval) + 1) & " categories"
.title.font.name = "Arial"
.title.font.size = 26
.title.font.bold = true
for i = 0 to ubound(yarr)
with .seriescollection.add
.interior.color = rgb(int(rnd*256), int(rnd*256), int(rnd*256))
.caption = "Cap" & i
.setdata c.chdimcategories, c.chdataliteral, xval
.setdata c.chdimvalues, c.chdataliteral, yarr(i)
with .datalabelscollection.add
.hasvalue = (ubound(yarr) = 0)
.haspercentage = (ubound(yarr) >= 1) and (ubound(yarr) < 3)
.font.name = "Arial"
.font.size = 6
.font.bold = false
.interior.color = rgb(255, 255, 255)
end with
end with
next
with .axes(c.chaxispositionbottom)
.font.name = "Arial"
.font.size = 8
.font.bold = false
.hastitle = true
.title.caption = "Bottomaxisname"
.title.font.name = "Arial"
.title.font.size = 10
.title.font.bold = true
end with
with .axes(c.chaxispositionleft)
.font.name = "Arial"
.font.size = 8
.font.bold = false
.majorunit = 500
.hasmajorgridlines = true
.hastitle = true
.title.caption = "Leftaxisname"
.title.font.name = "Arial"
.title.font.size = 10
.title.font.bold = true
end with
.haslegend = true
.legend.position = c.chlegendpositionbottom
.legend.font.name = "Arial"
.legend.font.size = 8
.legend.font.bold = false
.plotarea.interior.color = rgb(200, 200, 200)
end with
set c = nothing
set fillchart = chartspace
end function
class outputwindow
public ie, body, document, iequitclicked
private sub class_initialize()
set ie = wscript.createobject("internetexplorer.application", "ie_")
with ie
.menubar = false
.toolbar = false
.resizable = true
.statusbar = false
.addressbar = false
.visible = true
REM .fullscreen = true
.navigate "about:blank"
end with
set document = ie.document
document.write "<html><head><title>outputwindow</title></head><body></body></html>"
set body = document.getelementsbytagname("body")(0)
iequitclicked = false
end sub
public sub write(text)
document.write text & "<br>"
end sub
private sub class_terminate()
if not iequitclicked then
ie.quit
end if
set ie = nothing
end sub
end class
sub ie_onquit
display.iequitclicked = true
wscript.quit
end subЭкспорт растра
option explicit
dim chartspace, xval, yarr, file
' create chart
set chartspace = createobject("OWC11.ChartSpace") ' OWC10.ChartSpace | OWC11.ChartSpace
chartspace.clear
chartspace.refresh
' fill chart
randomdata xval, yarr
fillchart chartspace, xval, yarr
' export chart
file =wscript.scriptfullname & ".png"
chartspace.exportpicture file, "png", 1024, 768
msgbox "Saved to " & vbcrlf & file, 64, "OWC11.ChartSpace"
sub randomdata(xval, yarr)
' Create categories array and array of values arrays
dim catsqty, rowsqty, yval, i, j
randomize
catsqty = 4 + int(rnd * 6) ' categories qty in each row
rowsqty = int(sqr(rnd) * 4) ' rows qty
redim xval(catsqty)
for i = 0 to catsqty
xval(i) = "Cat" & i
next
redim yval(catsqty)
redim yarr(rowsqty)
for j = 0 to rowsqty
for i = 0 to catsqty
yval(i) = int(rnd * 1000)
next
yarr(j) = yval
next
end sub
function fillchart(chartspace, xval, yarr)
dim c, i
set c = chartspace.constants
with chartspace.charts.add
.type = c.chcharttypecolumnstacked3d
.hastitle = true
.title.caption = "Chart with " & (ubound(yarr) + 1) & " rows in " & (ubound(xval) + 1) & " categories"
.title.font.name = "Arial"
.title.font.size = 26
.title.font.bold = true
for i = 0 to ubound(yarr)
with .seriescollection.add
.interior.color = rgb(int(rnd*256), int(rnd*256), int(rnd*256))
.caption = "Cap" & i
.setdata c.chdimcategories, c.chdataliteral, xval
.setdata c.chdimvalues, c.chdataliteral, yarr(i)
with .datalabelscollection.add
.hasvalue = (ubound(yarr) = 0)
.haspercentage = (ubound(yarr) >= 1) and (ubound(yarr) < 3)
.font.name = "Arial"
.font.size = 6
.font.bold = false
.interior.color = rgb(255, 255, 255)
end with
end with
next
with .axes(c.chaxispositionbottom)
.font.name = "Arial"
.font.size = 8
.font.bold = false
.hastitle = true
.title.caption = "Bottomaxisname"
.title.font.name = "Arial"
.title.font.size = 10
.title.font.bold = true
end with
with .axes(c.chaxispositionleft)
.font.name = "Arial"
.font.size = 8
.font.bold = false
.majorunit = 500
.hasmajorgridlines = true
.hastitle = true
.title.caption = "Leftaxisname"
.title.font.name = "Arial"
.title.font.size = 10
.title.font.bold = true
end with
.haslegend = true
.legend.position = c.chlegendpositionbottom
.legend.font.name = "Arial"
.legend.font.size = 8
.legend.font.bold = false
.plotarea.interior.color = rgb(200, 200, 200)
end with
set c = nothing
set fillchart = chartspace
end functionСпособ в общем-то древний, но на форуме не был затронут, кому-нибудь может пригодиться.
Источники:
http://support.microsoft.com/kb/235885
http://msdn.microsoft.com/en-us/library … e.10).aspx
http://support.alphasoftware.com/AlphaF … hart_Types
http://aspnetresources.com/articles/off … components
http://javascript.ru/forum/dom-window/3 … tivex.html
’ҐЄгй п Є®¤®ў п бва Ёж : 1251

