PPWIZARD is a free preprocessor for HTML, REXX, Visual Basic or any text files.
[Bottom][Contents][Search][Prev]: #import - EXCEL via VbScript[Next]: Create Multiple Files From Template
\ -> Examples / Tips -> Automatically Create Chart Images

Automatically Create Chart Images

PPWIZARD is all about automation and reducing your work load. For this reason I have included a crude example of how a bar/pie or other type of chart can be automatically created.

This sample shows the data hardcoded, in real life it would come from a database or some other source. The source has enough detail (keywords!) in it that you should have little trouble finding more information on the web.

The data could be "hardcoded" via an SQL import (ie generate VB code instead of HTML table) if the VbScript was generated in a similar manner to that shown in the Excel example.

This is a sample of a "GIF" file I created with the VbScript:

This bar chart was automatically created by the VbScript below

The VbScript code follows (tested in Windows 2000 with Office 2000):

'--- Initialize chart -------------------------------------------------------
set oChart = WScript.CreateObject("OWC.Chart")
'oChart.Clear()
'oChart.Refresh()

'--- Some Handy "hooks" -----------------------------------------------------
set Con   = oChart.Constants           'Access to predefined constants
set Chart = oChart.Charts.Add
set SC    = Chart.SeriesCollection
set SCA   = Chart.SeriesCollection.Add  'Need! (VbScript bug?, looks likely)

'--- Set colors -------------------------------------------------------------
'oChart.Border.Color = Con.chColorNone
'oChart.Border.Color = Con.chColor

'--- Add Title --------------------------------------------------------------
Chart.hasTitle        = true
Chart.title.caption   = "Dennis' Test Chart"
Chart.title.font.name = "tahoma"
Chart.title.font.size = 10
Chart.title.font.bold = true

'--- Make up some data ------------------------------------------------------
dim x(10), y(10)
x(1) = "RED"
x(2) = "GREEN"
x(3) = "BLUE"
y(1) = "20"
y(2) = "61"
y(3) = "70"

'--- Chart above data -------------------------------------------------------
SCA.setData Con.chDimCategories, Con.chDataLiteral, x
SCA.setData Con.chDimValues,     Con.chDataLiteral, y

'--- Want Exploded PIE Chart (default is bar graph) -------------------------
'Chart.Type = Con.chChartTypePie
'SC.Item(0).Explosion = 10

'--- Label the values -------------------------------------------------------
'with SC(0).DataLabelsCollection.Add            'Add values to slices/on top of bar
'   .Interior.Color = RGB(255, 255, 255)
'   .Font.Size      = 8
'end with

'--- Create the GIF ---------------------------------------------------------
oChart.ExportPicture "c:\tmp\excel\t_chart.gif", "gif", 200, 200


email me  any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Search][Prev]: #import - EXCEL via VbScript[Next]: Create Multiple Files From Template


PPWIZARD Manual
My whole website and this manual itself was developed using PPWIZARD (free preprocessor written by Dennis Bareis)
Sunday November 05 2017 at 10:00am