Microsoft KB Archive/135348

= How To Update a Graph in a Form =

Article ID: 135348

Article Last Modified on 7/13/2004

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 6.0 Professional Edition
 * Microsoft Visual FoxPro 3.0b for Macintosh

-



This article was previously published under Q135348



SUMMARY
This article shows by example how to update a graph on a form in Microsoft Visual FoxPro.



MORE INFORMATION
To update a graph in previous versions of FoxPro, you may have used the DO UPDATEGRPH IN GENGRAPH.APP WITH command. Microsoft Visual FoxPro does not include Gengraph.app, so a new approach must be taken.

Step-by-Step Example
 Open or switch to Microsoft Visual FoxPro, and create a new table called Mydata.dbf that contains a character field called Myseries and three numeric fields called Mydata1, Mydata2 and Mydata3. Add five records to the table that contain random numbers between 1 and 20 in the three numeric fields and 'Series 1', 'Series 2', 'Series 3', and so on in the character field. Create a new form called Myform, and add the table Mydata to the data environment of the form. Add a grid to the form. Use the Property window to set the RecordSource property of the grid to Mydata. Leave the RecordSourceType set to Alias.  With the Mydata table open in the active work area, type the following command in the Command window: DO (_GENGRAPH) WITH "MYDATA" This will start the Graph Wizard, so you can create the initial graph for the form. Add the three numeric fields to the Data Series list box and the character field to the Axis field of the wizard. Click the Next button, and follow the instructions provided by the wizard. Save the graph as Mygraph.dbf when prompted. In Visual FoxPro 6.0, by default a graph is saved to a form. In step 4 of the wizard, choose the option button that that says "Save graph to a table."  Add the Mygraph.dbf table to the data environment of the form. Add an OLE Bound control to the form. Using the Property window, set the ControlSource of the OLE Bound control to MYGRAPH.OLEGRAPH, and set the Stretch property of the OLE Bound control to Isometric.</li>  Add a command button to the form, and change its Caption property to Update. Place the following code in the command button's Click event procedure: SELECT * FROM MYDATA INTO CURSOR MYCURSOR TAB = CHR(09) CRLF = CHR(13) + CHR(10) SELECT MYCURSOR NEWDATA = TAB + "Label A" + TAB + " Label B " + TAB ; + " Label C " + CRLF SCAN NEWDATA = NEWDATA + MYSERIES + TAB + STR(MYDATA1) + TAB ; + STR(MYDATA2) + TAB + STR(MYDATA3) + CRLF ENDSCAN SELECT MYGRAPH APPEND GENERAL Mygraph.Olegraph DATA NEWDATA THISFORM.REFRESH </li> Save and run the form. Make some changes to the data in the grid, and click the Update button. Note that the changes made to the grid are reflected in the graph.</li></ol>

<div class="references_section">