Advertisement
omegastripes

OWC_Chart_Exportpicture.vbs

Sep 15th, 2013
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. option explicit
  2. dim chartspace, xval, yarr, file
  3.  
  4. ' create chart
  5. set chartspace = createobject("OWC11.ChartSpace") ' OWC10.ChartSpace | OWC11.ChartSpace
  6. chartspace.clear
  7. chartspace.refresh
  8.  
  9. ' fill chart
  10. randomdata xval, yarr
  11. fillchart chartspace, xval, yarr
  12.  
  13. ' export chart
  14. file =wscript.scriptfullname & ".png"
  15. chartspace.exportpicture file, "png", 1024, 768
  16. msgbox "Saved to " & vbcrlf & file, 64, "OWC11.ChartSpace"
  17.  
  18. sub randomdata(xval, yarr)
  19.     ' Create categories array and array of values arrays
  20.     dim catsqty, rowsqty, yval, i, j
  21.     randomize
  22.     catsqty = 4 + int(rnd * 6) ' categories qty in each row
  23.     rowsqty = int(sqr(rnd) * 4) ' rows qty
  24.     redim xval(catsqty)
  25.     for i = 0 to catsqty
  26.         xval(i) = "Cat" & i
  27.     next
  28.     redim yval(catsqty)
  29.     redim yarr(rowsqty)
  30.     for j = 0 to rowsqty
  31.         for i = 0 to catsqty
  32.             yval(i) = int(rnd * 1000)
  33.         next
  34.         yarr(j) = yval
  35.     next
  36. end sub
  37.  
  38. function fillchart(chartspace, xval, yarr)
  39.     dim c, i
  40.     set c = chartspace.constants
  41.     with chartspace.charts.add
  42.         .type = c.chcharttypecolumnstacked3d
  43.         .hastitle = true
  44.         .title.caption = "Chart with " & (ubound(yarr) + 1) & " rows in " & (ubound(xval) + 1) & " categories"
  45.         .title.font.name = "Arial"
  46.         .title.font.size = 26
  47.         .title.font.bold = true
  48.         for i = 0 to ubound(yarr)
  49.             with .seriescollection.add
  50.                 .interior.color = rgb(int(rnd*256), int(rnd*256), int(rnd*256))
  51.                 .caption = "Cap" & i
  52.                 .setdata c.chdimcategories, c.chdataliteral, xval
  53.                 .setdata c.chdimvalues, c.chdataliteral, yarr(i)
  54.                 with .datalabelscollection.add
  55.                     .hasvalue = (ubound(yarr) = 0)
  56.                     .haspercentage = (ubound(yarr) >= 1) and (ubound(yarr) < 3)
  57.                     .font.name = "Arial"
  58.                     .font.size = 6
  59.                     .font.bold = false
  60.                     .interior.color = rgb(255, 255, 255)
  61.                 end with
  62.             end with
  63.         next
  64.         with .axes(c.chaxispositionbottom)
  65.             .font.name = "Arial"
  66.             .font.size = 8
  67.             .font.bold = false
  68.             .hastitle = true
  69.             .title.caption = "Bottomaxisname"
  70.             .title.font.name = "Arial"
  71.             .title.font.size = 10
  72.             .title.font.bold = true
  73.         end with
  74.         with .axes(c.chaxispositionleft)
  75.             .font.name = "Arial"
  76.             .font.size = 8
  77.             .font.bold = false
  78.             .majorunit = 500
  79.             .hasmajorgridlines = true
  80.             .hastitle = true
  81.             .title.caption = "Leftaxisname"
  82.             .title.font.name = "Arial"
  83.             .title.font.size = 10
  84.             .title.font.bold = true
  85.         end with
  86.         .haslegend = true
  87.         .legend.position = c.chlegendpositionbottom
  88.         .legend.font.name = "Arial"
  89.         .legend.font.size = 8
  90.         .legend.font.bold = false
  91.         .plotarea.interior.color = rgb(200, 200, 200)
  92.     end with
  93.     set c = nothing
  94.     set fillchart = chartspace
  95. end function
  96.  
  97. ' links
  98.  
  99. ' http://support.microsoft.com/kb/235885
  100. ' http://msdn.microsoft.com/en-us/library/office/aa155723(v=office.10).aspx
  101. ' http://support.alphasoftware.com/AlphaFiveHelp/Xdialog/XY_Graph.htm#Complete_List_of_Supported_Chart_Types
  102. ' http://aspnetresources.com/articles/office_web_components
  103. ' http://javascript.ru/forum/dom-window/32482-ne-otobrazhaetsya-dinamicheskijj-activex.html
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement