Friday, November 19, 2004

MS Graph Again

VFP is a very powerful tool. You can do almost everything related with business application, but NOT Graphing. VFP developers got to use third party tool to generate and print graph. One of the most common graphing tool for VFP developers is MS Graph. MS Graph is come with MS Excel. Therefore, make sure MS Excel is installed in order to use MS Graph.

You may notice that, questions about using MS Graph are posted to forum again, again and again. Therefore, I decided to blog abit about it.

There are couple of way to use MS Graph. AFAIK, there are :
  1. Automate Microsoft Excel via OLE Automation
  2. Use VFP AutoGraph FFC or VFP GenGraph wizard
  3. Use General field to link data to MS Graph.
Each of them has its pros and cons:

Automate Microsoft Excel via OLE Automation
Since we are automating MS Excel, then we can do anything MS Excel offer, instead of just graphing. In other words, we can not only generate graph, but also can use MS Excel features such as formatting, table drawing, formula calculation and etc. It makes our graph report looks more attractive and modern.

Also, the generated graph could be saved on disk for future use.

It is slower and required more resources since not only MS Graph is initiated but also MSExcel.Application.

Use VFP AutoGraph FFC or VFP GenGraph wizard
This is the easiest way to generate graph. We only required to follow the wizard steps by steps with informative guideness on wizard form and press "Finish". Graph will be generated. No coding is required.

Refresh MS Graph content is not straight forward for VFP developers. For more info about it, pls check my previous blog.

The generated graph couldn't be printed. We can't bind it to VFP report field control.

Use General field to link data to MS Graph
We still have 100% of control to our graph via MS Graph automation provided without need to automate whole MSExcel.Application. We can allow user to preview it on form, and also print using VFP native report system. Alot more information available on web, help files and VFP sample code.

I can't think of any for now.

This is a simple sample code file I created using General field appraoch. In fact, I use this appraoch alot for graphing and it works very well till now.

For preview and print graph in VFP report
  1. Create a report.
  2. Place Picture/ActiveX Bound Control on report's details band.
  3. Select Field option in Picture From option box.
  4. Key in "csrGraph.myGraph" in field textbox.
  5. Resize the control to size as need.
  6. Preview report.
I hope this could help anyone who new to MS Graph. If anyone has any comments or more info or anything I mentioned is wrong, pls comment here. Thank you.

BTW, remember to get VBAGR10.chm help file. It would save us alot of time.

Updated: Article Graphing in VFP by Ted Roche. Thank you.


At 11:28 PM, Blogger Ted Roche said...

I presented a session on blogging at the 2003 DevCon. You can find the paper at

At 9:05 AM, Blogger Chan Kok Kiet (John Jones) said...

Thank you Ted Roche for sharing. :)


Post a Comment

<< Home