Manipulate Display Characteristics of a Graph

File: SAMPLES\SOLUTION\OLE\OLEGRAPH.SCX

This sample shows how to incorporate MS Graph into your applications. MS Graph ships with Visual FoxPro and can also be included in your distributed applications. MS Graph 5.0 is an OLE Automation Server that Visual FoxPro can automate using the standard CREATEOBJECT( ) function. With Visual FoxPro, Graph objects can be embedded in either bound or unbound OLE Controls. An OleBoundControl (bound to a General field) is the only way to programmatically insert data into a graph.

MS Graph’s automation support provides access only to a graph object, not its datasheet. Data can be inserted into a Graph only with the APPEND GENERAL command on a General field. The following code uses the HasLegend property and is an example of automation.

cGData = ""+TAB+"Cats"+TAB+"Dogs"+CRLF+;
		"1994"+TAB+"11"+TAB+"22"+CRLF+;
		"1995"+TAB+"33"+TAB+"44"+CRLF+;
		"1996"+TAB+"55"+TAB+"55"+CRLF
APPEND GENERAL gen1 CLASS "msgraph.chart" DATA m.cGData
THIS.OleBoundControl1.ControlSource = "Gen1"
THIS.OleBoundControl1.HasLegend = .F.

The APPEND GENERAL command in this case creates a new chart object. If you do not include the CLASS “msgraph.chart” clause, then the chart is merely updated. The CLASS clause will create a new chart and override any existing formatting.