<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; VBS: Пример построения диаграмм с помощью OWC]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=8671&amp;type=atom" />
	<updated>2013-09-15T22:06:35Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=8671</id>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Пример построения диаграмм с помощью OWC]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=75395#p75395" />
			<content type="html"><![CDATA[<p>OFF: Да... Всё новое, это хорошо забытое старое... ) Я с его помощью и диаграммы строил и CAPTCHA генерил. ) Удобный компонент.</p>]]></content>
			<author>
				<name><![CDATA[Xameleon]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=8836</uri>
			</author>
			<updated>2013-09-15T22:06:35Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=75395#p75395</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[VBS: Пример построения диаграмм с помощью OWC]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=75394#p75394" />
			<content type="html"><![CDATA[<p>Доброго всем времени суток. Хочу привести пример построения диаграмм с помощью компонента <strong>ChartSpace</strong> из <strong>Office Web Components</strong>, поставляющегося в комплекте <strong>MS Office</strong> 2000 (OWC 9), 2003 (OWC 10) и XP (OWC 11). В данном случае используется библиотека <em>%CommonProgramFiles%\microsoft shared\Web Components\11\OWC11.DLL</em></p><p><strong>В окне браузера</strong><br /></p><div class="codebox"><pre><code>option explicit
dim display, chartspace, xval, yarr

&#039; create ie window for output
set display = new outputwindow

&#039; create chart
set chartspace = display.document.createelement(&quot;object&quot;)
with chartspace
    .id = &quot;ChartSpace&quot;
    .setattribute &quot;width&quot;, &quot;100%&quot;
    .setattribute &quot;height&quot;, &quot;100%&quot;
    &#039; OWC10.ChartSpace clsid:0002E546-0000-0000-C000-000000000046
    &#039; OWC11.ChartSpace clsid:0002E55D-0000-0000-C000-000000000046
    .setattribute &quot;classid&quot;, &quot;clsid:0002E55D-0000-0000-C000-000000000046&quot;
    .clear
    .refresh
end with

&#039; fill and append chart
randomdata xval, yarr
display.body.appendchild fillchart(chartspace, xval, yarr)

do
    wscript.sleep 100
loop

sub randomdata(xval, yarr)
    &#039; Create categories array and array of values arrays
    dim catsqty, rowsqty, yval, i, j
    randomize
    catsqty = 4 + int(rnd * 6) &#039; categories qty in each row
    rowsqty = int(sqr(rnd) * 4) &#039; rows qty
    redim xval(catsqty)
    for i = 0 to catsqty
        xval(i) = &quot;Cat&quot; &amp; 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 = &quot;Chart with &quot; &amp; (ubound(yarr) + 1) &amp; &quot; rows in &quot; &amp; (ubound(xval) + 1) &amp; &quot; categories&quot;
        .title.font.name = &quot;Arial&quot;
        .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 = &quot;Cap&quot; &amp; i
                .setdata c.chdimcategories, c.chdataliteral, xval
                .setdata c.chdimvalues, c.chdataliteral, yarr(i)
                with .datalabelscollection.add
                    .hasvalue = (ubound(yarr) = 0)
                    .haspercentage = (ubound(yarr) &gt;= 1) and (ubound(yarr) &lt; 3)
                    .font.name = &quot;Arial&quot;
                    .font.size = 6
                    .font.bold = false
                    .interior.color = rgb(255, 255, 255)
                end with
            end with
        next
        with .axes(c.chaxispositionbottom)
            .font.name = &quot;Arial&quot;
            .font.size = 8
            .font.bold = false
            .hastitle = true
            .title.caption = &quot;Bottomaxisname&quot;
            .title.font.name = &quot;Arial&quot;
            .title.font.size = 10
            .title.font.bold = true
        end with
        with .axes(c.chaxispositionleft)
            .font.name = &quot;Arial&quot;
            .font.size = 8
            .font.bold = false
            .majorunit = 500
            .hasmajorgridlines = true
            .hastitle = true
            .title.caption = &quot;Leftaxisname&quot;
            .title.font.name = &quot;Arial&quot;
            .title.font.size = 10
            .title.font.bold = true
        end with
        .haslegend = true
        .legend.position = c.chlegendpositionbottom
        .legend.font.name = &quot;Arial&quot;
        .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(&quot;internetexplorer.application&quot;, &quot;ie_&quot;)
        with ie
            .menubar = false
            .toolbar = false
            .resizable = true
            .statusbar = false
            .addressbar = false
            .visible = true
            REM .fullscreen = true
            .navigate &quot;about:blank&quot;
        end with
        set document = ie.document
        document.write &quot;&lt;html&gt;&lt;head&gt;&lt;title&gt;outputwindow&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;&quot;
        set body = document.getelementsbytagname(&quot;body&quot;)(0)
        iequitclicked = false
    end sub
    
    public sub write(text)
        document.write text &amp; &quot;&lt;br&gt;&quot;
    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</code></pre></div><p><strong>Экспорт растра</strong><br /></p><div class="codebox"><pre><code>option explicit
dim chartspace, xval, yarr, file

&#039; create chart
set chartspace = createobject(&quot;OWC11.ChartSpace&quot;) &#039; OWC10.ChartSpace | OWC11.ChartSpace
chartspace.clear
chartspace.refresh

&#039; fill chart
randomdata xval, yarr
fillchart chartspace, xval, yarr

&#039; export chart
file =wscript.scriptfullname &amp; &quot;.png&quot;
chartspace.exportpicture file, &quot;png&quot;, 1024, 768
msgbox &quot;Saved to &quot; &amp; vbcrlf &amp; file, 64, &quot;OWC11.ChartSpace&quot;

sub randomdata(xval, yarr)
    &#039; Create categories array and array of values arrays
    dim catsqty, rowsqty, yval, i, j
    randomize
    catsqty = 4 + int(rnd * 6) &#039; categories qty in each row
    rowsqty = int(sqr(rnd) * 4) &#039; rows qty
    redim xval(catsqty)
    for i = 0 to catsqty
        xval(i) = &quot;Cat&quot; &amp; 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 = &quot;Chart with &quot; &amp; (ubound(yarr) + 1) &amp; &quot; rows in &quot; &amp; (ubound(xval) + 1) &amp; &quot; categories&quot;
        .title.font.name = &quot;Arial&quot;
        .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 = &quot;Cap&quot; &amp; i
                .setdata c.chdimcategories, c.chdataliteral, xval
                .setdata c.chdimvalues, c.chdataliteral, yarr(i)
                with .datalabelscollection.add
                    .hasvalue = (ubound(yarr) = 0)
                    .haspercentage = (ubound(yarr) &gt;= 1) and (ubound(yarr) &lt; 3)
                    .font.name = &quot;Arial&quot;
                    .font.size = 6
                    .font.bold = false
                    .interior.color = rgb(255, 255, 255)
                end with
            end with
        next
        with .axes(c.chaxispositionbottom)
            .font.name = &quot;Arial&quot;
            .font.size = 8
            .font.bold = false
            .hastitle = true
            .title.caption = &quot;Bottomaxisname&quot;
            .title.font.name = &quot;Arial&quot;
            .title.font.size = 10
            .title.font.bold = true
        end with
        with .axes(c.chaxispositionleft)
            .font.name = &quot;Arial&quot;
            .font.size = 8
            .font.bold = false
            .majorunit = 500
            .hasmajorgridlines = true
            .hastitle = true
            .title.caption = &quot;Leftaxisname&quot;
            .title.font.name = &quot;Arial&quot;
            .title.font.size = 10
            .title.font.bold = true
        end with
        .haslegend = true
        .legend.position = c.chlegendpositionbottom
        .legend.font.name = &quot;Arial&quot;
        .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</code></pre></div><p>Способ в общем-то древний, но на форуме не был затронут, кому-нибудь может пригодиться.</p><p>Источники:<br /><a href="http://support.microsoft.com/kb/235885">http://support.microsoft.com/kb/235885</a><br /><a href="http://msdn.microsoft.com/en-us/library/office/aa155723(v=office.10).aspx">http://msdn.microsoft.com/en-us/library … e.10).aspx</a><br /><a href="http://support.alphasoftware.com/AlphaFiveHelp/Xdialog/XY_Graph.htm#Complete_List_of_Supported_Chart_Types">http://support.alphasoftware.com/AlphaF … hart_Types</a><br /><a href="http://aspnetresources.com/articles/office_web_components">http://aspnetresources.com/articles/off … components</a><br /><a href="http://javascript.ru/forum/dom-window/32482-ne-otobrazhaetsya-dinamicheskijj-activex.html">http://javascript.ru/forum/dom-window/3 … tivex.html</a></p>]]></content>
			<author>
				<name><![CDATA[omegastripes]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=29228</uri>
			</author>
			<updated>2013-09-15T21:12:13Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=75394#p75394</id>
		</entry>
</feed>
