Share via


Graph Equations on a Form

File: ...\Samples\Solution\Forms\Graphics\Graph.scx

This sample shows how to graph equations with form graphics. The user can scale the equation by choosing the Zoom command buttons. The user also can move the graph's origin by clicking and dragging.

The graphing engines for this sample are in two programs: Cgraph.prg and Pgraph.prg. CGRAPH graphs equations based on Cartesian coordinates. PGRAPH graphs equations based on Polar coordinates. These programs use the PSet and Line methods of a form to draw the equation.

The following code, associated with the OneGraph method of the form set, runs the CGRAPH program when a user chooses the Graph button:

THISFORMSET.frmGraph.Draw

   DO cgraph WITH ;
      graph.equation, ; 
      graph.step, ;
      graph.ecolor, ;
      graph.connect, ;
      THISFORMSET.nFormX, ;
      THISFORMSET.nFormY, ;
      .F., ;
      THISFORMSET.frmgraph, ;
      THISFORMSET.nFormScale

The following table lists the parameters for CGRAPH:

Parameter Type Description
equation C The equation in terms of X. Will plot the answer as Y.
step N Step increment.
ecolor N Equation color.
connect L Whether the previous point is connected to the current point with a line.
nFormX N Point on form where x = 0
nFormY N Point on form where y = 0
lAddCoords   Whether to draw coordinate lines.
frmgraph C Name of the form to write to.
nFormScale N Scale to graph the equation at.

See Also

Graph Object | Refresh a Graph in a Form | Solutions Sample Overview | Visual FoxPro Foundation Classes A-Z