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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create graph images dynamically 2

Status
Not open for further replies.

foxdev

Programmer
Feb 11, 2000
1,995
US
Perhaps like some of you, I find that the Fox language is so rich with string handling tools that I often use if for a lot of chores. One of these includes generating static reports in the form of HTML pages.

But many of my reports includes lots of numbers and time components, so a graph or two on each report would greatly enhance readability and usefulness. But I couldn't find a tool that would allow me to create a graph based on the data I had collected and generate an image file such as a GIF.

I posted the question [thread253-53244] in the Web Sie Designers forum asking for tool recommendations for creating a graph on the fly. I received some good answers, but none that exactly fit the problem. I eventually stumbled upon it: Office Web Components. OWC may be installed on your machine, as it comes with a variety of Microsoft products.

Below is my code for creating a basic graph using a cursor/table:

[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

if empty(alias())
wait window "No table/alias open in current work area" timeout 200
return
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 empty(cCaption)
cCaption = "Graph"
endif

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

oChart = CreateObject("OWC.Chart")

oChart.Charts.Add
oChart.Charts(0).Type = oChart.Constants.chChartTypeColumnClustered
oChart.Charts(0).SeriesCollection.Add
oChart.Charts(0).SeriesCollection(0).Caption = cCaption
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)
oChart.Charts(0).HasLegend = .F.
oChart.Charts(0).HasTitle = .T.

oChart.ExportPicture(cOutFile, "gif", 500, 300)

release oChart
[/tt]
Robert Bradley
Do you have too much money? Visit
 
Hi Robert
This was a good one, ty
For any programmer want to know more about this, find the file Msowcvba.chm in you computer, read & have fun
Walid
Engwam@Hotmail.com
 
I agreee. Nice tip Robert, worthy of a FAQ - 'How to create a graph image file using office automation'.

Just a side bar:

<snipped>
go top
for i = 1 to reccount()

aLabels(i) = alltrim(evaluate(field(1)))
aValues(i) = evaluate((field(2)))
skip
endfor


I find it hard to believe that an expert VFP programmer is using a FOR command to loop thru a table when VFP provides such a sweet function in the SCAN command. ;-)

JK...I know you probably thru it together in a hurry. Jon Hawkins
jonscott8@yahoo.com

The World Is Headed For Mutiny,
When All We Want Is Unity. - Creed
 
I use SCAN 98% of the time. The reason I used FOR this time is because I needed a counter anyway for the array element row, so I killed two birds with one construct. Yes, I could have used RECNO(), but in my program I'm not assuming that there will be no deleted records, so I thought it a bad choice.

BTW, I never use i as a parameter in real life. On the stage, its easy to type and generally familiar to others; I would use something like nRowNum in my own code.

So there. ::)

And yes, I did sort of throw it together, but not in a time-constrained fashion. I had copy/pasted code from a VBScript example and went through and translated the code, testing it often. That left in a lot of...informalness that I wouldn't normally put in my &quot;from scratch&quot; code.

And yes, Jon, I know you were just kidding. Believe me, I make tons of mistakes each day, and as I get older my CPU doesn't work as efficiently as it used to; therefore, I'm pretty apt to take the long road at times. You are one of the reasons the VFP forum is as great as it is, and I always welcome your feedback - kidding or not. Robert Bradley
Do you have too much money? Visit
 
AFA using the counter to correlate with the array element and not wanting to use RECNO(), I presumed thats why you had used the for loop. (-: But then, couldn't you achieve the same result with:

i=1
SCAN

aLabels(i) = alltrim(evaluate(field(1)))
aValues(i) = evaluate((field(2)))
i=1+i
ENDSCAN


You are one of the reasons the VFP forum is as great as it is, and I always welcome your feedback

:~/ Jon Hawkins
jonscott8@yahoo.com

The World Is Headed For Mutiny,
When All We Want Is Unity. - Creed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top