Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Graphs in VFP 2

Status
Not open for further replies.

ikh

Programmer
Apr 17, 2001
24
CA
How to convert graph (created by MS Graph) from General field to JPEG/GIF file???
 
This doesn't directly answer your question, but I spent a week trying to find the right solution for generating and using graphs with VFP. I ended up using the OWC - Office Web Components supplied by Microsoft to generate standalone images. It works reliably and fast. Let me know if you need samples. Robert Bradley
teaser.jpg

 
I would appreciate if somebody can provide some
OWC - Office Web Components examples.
 
I hesitate to post this much code in a thread, but I think all of this would be helpful and give you a good headstart.

Essentially, you have an open table/cursor where the first column is assumed to be the labels and the second column is assumed to be the value. As you'll note, I've kludged in support for a second value column, but haven't gotten around to expanding it and making it more flexible.

An example select statement that could be used to feed the graph:

[tt]select State, count(*) from MyTable group by State[/tt]

The result will be a GIF file. Many of the parameters are optional (such as image size), so its fairly simple to use.

------------

[tt]* -- makes a chart using the currently open table/cursor
* -- the first column should be the X-axis labels,
* -- and the rest of the columns should be the Y-axis values

Parameters cOutFile, cCaption, cChartType, nWidthPixels, nHeightPixels, nValueColumns

set asserts on

if empty(alias())
wait window "No table/alias open in current work area" timeout 200
return .F.
endif

if reccount() = 0
wait window "No records in alias" timeout 200
return .F.
endif

if empty(cChartType)
cChartType = "BAR"
else
cChartType = upper(cChartType)
endif

if empty(nWidthPixels)
nWidthPixels = 500
endif
if empty(nHeightPixels)
nHeightPixels = 300
endif

if empty(nValueColumns)
nValueColumns = 1
endif

* -- put the contents into an array
dimension aLabels(reccount())
dimension aValues(reccount())
go top
for i = 1 to reccount()
aLabels(i) = alltrim(evaluate(field(1)))
aValues(i) = evaluate((field(2)))
skip
endfor
if nValueColumns = 2
dimension aLabels2(reccount())
dimension aValues2(reccount())
go top
for i = 1 to reccount()
aLabels2(i) = alltrim(evaluate(field(1)))
aValues2(i) = evaluate((field(3)))
skip
endfor
endif

if empty(cCaption)
cCaption = "Graph"
endif

if empty(cOutFile)
cOutFile = "chart.gif"
endif

* -- Create a Chart Object
oChart = CreateObject("OWC.Chart")

if vartype(oChart) <> &quot;O&quot;
wait window &quot;Could not create OWC object&quot; timeout 30
return .F.
endif

lLegend = .F.
* -- determine graph type
do case
case cChartType == &quot;COLUMN CLUSTERED&quot;
cGraphType = oChart.Constants.chChartTypeColumnClustered
case cChartType == &quot;COLUMN STACKED&quot;
cGraphType = oChart.Constants.chChartTypeColumnStacked
case cChartType == &quot;AREA&quot;
cGraphType = oChart.Constants.chChartTypeArea
case cChartType == &quot;AREA STACKED&quot;
cGraphType = oChart.Constants.chChartTypeAreaStacked
lLegend = .T.
case cChartType == &quot;PIE&quot;
cGraphType = oChart.Constants.chChartTypePie
lLegend = .T.
case cChartType == &quot;PIE EXPLODED&quot;
cGraphType = oChart.Constants.chChartTypePieExploded
lLegend = .T.
case cChartType == &quot;PIE PERCENT&quot;
cGraphType = oChart.Constants.chChartTypePie
lLegend = .T.
case cChartType == &quot;LINE&quot;
cGraphType = oChart.Constants.chChartTypeLine
case cChartType == &quot;DOUGHNUT&quot;
cGraphType = oChart.Constants.chChartTypeDoughnut
case cChartType == &quot;BUBBLE&quot;
cGraphType = oChart.Constants.chChartBubble
otherwise
cGraphType = oChart.Constants.chChartTypeColumnClustered
endcase



*** oChart.Border.Color = c.chColorNone

oChart.Charts.Add
oChart.Charts(0).Type = cGraphType && oChart.Constants.chChartTypeColumnClustered
oChart.Charts(0).HasTitle = .T.
oChart.Charts(0).Title.Caption = cCaption

oChart.Charts(0).SeriesCollection.Add
oChart.Charts(0).SeriesCollection(0).Caption = field(2)
if &quot;PIE PERCENT&quot; $ upper(cChartType)
oDL = oChart.Charts(0).SeriesCollection(0).DataLabelsCollection.Add
oDL.HasPercentage = .T.
oDL.HasCategoryName = .F.
oDL.HasValue = .F.
endif
oChart.Charts(0).SeriesCollection(0).SetData(oChart.Constants.chDimCategories, oChart.Constants.chDataLiteral, @aLabels)
oChart.Charts(0).SeriesCollection(0).SetData(oChart.Constants.chDimValues, oChart.Constants.chDataLiteral, @aValues)

if nValueColumns = 2
oChart.Charts(0).SeriesCollection.Add
oChart.Charts(0).SeriesCollection(1).Caption = field(3)
if &quot;PIE PERCENT&quot; $ upper(cChartType)
oDL = oChart.Charts(0).SeriesCollection(1).DataLabelsCollection.Add
oDL.HasPercentage = .T.
oDL.HasCategoryName = .F.
oDL.HasValue = .F.
endif
oChart.Charts(0).SeriesCollection(1).SetData(oChart.Constants.chDimCategories, oChart.Constants.chDataLiteral, @aLabels2)
oChart.Charts(0).SeriesCollection(1).SetData(oChart.Constants.chDimValues, oChart.Constants.chDataLiteral, @aValues2)
endif

oChart.Charts(0).HasLegend = lLegend

oChart.ExportPicture(cOutFile, &quot;gif&quot;, nWidthPixels, nHeightPixels)

release oChart
[/tt]
Robert Bradley
teaser.jpg

 
Thanks foxdev I appreciate your time and help.
 
Hello.

Robert, you're the man!

Thank you. Grigore Dolghin
Class Software
Bucharest, Romania
 
If you guys try it and it works for you, I'll FAQ it for posterity.

I generate a couple dozen reports automatically each night. I use VFP to do the data collection and analysis, and spit out HTML with links to the generated GIF graphs.

Keep in mind that OWC has a lot more capabilities than just the little part I'm exploiting here. You can find some help files by searching on your computer for files named MSOWC*.CHM. Robert Bradley
teaser.jpg

 
Robert,
I see that you generate a man reports automatically each night. You use VFP to do the data collection and analysis, and spit out HTML with links to the generated GIF graphs.

I ask you a question? Can I make a graf of the totals of the collections that are taken up each sunday in chruch?
Or the averages of Baptisms or wedding per month over a period of ten years? I can see the tremendous advantage of a graf.

I will be anxious to hear your response. Johnjames...

juandiegomcc@yahoo.com



 
Robert,

I searched my computer for MSOWL and found several .dlls and an .sll (whatever that is), but no help files. These were all in Microsoft Office 10 directories. Should I look in some other help file? Dave Dardinger
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top