Wiki Home

MSChart Control Examples


Namespace: WIN_COM_API
The following are excerpts from Pinnacle Software for their Premium Graphics Server.

For further assistance you can send E-Mail to our support staff: Support@GraphicsServer.com

Host Language: Visual FoxPro
Product: Graphics Server
Version Number: 4.0x

Key-Words: USAGE VFP PROPERTIES DATA BINDING FOXPRO
Issue:
How do I move my Database Values into the Graphics Server .OCX
Short Answer:
By setting the Properties as per example:
Discussion:
The following example is designed to move values from the current Database into the Graphics Server .OCX. This is currently the only way to bind the Data to Visual FoxPro.

Example Code:
 
* Code from within the Test Form. 
* I've designed this code to load a Test database with Known Data
Use SCXTest
If RecCount() < 50
   For I = RecCount() + 1 to 50
        Append Blank
        Replace Field1 with I
        Replace Field2 with I + 10
        Replace Field3 with I + 20
    Next
EndIf
Do Form FormTest

* Code from within First Command Button
* This command button shows how to move my data from the Database
* to Graphics Server .Data() Array Property

* First, Set the variable Graph1 to the Graph object from the Form
Graph1 = ThisForm.OleControl1

* Set the Number of Points to the number of records from the SQL Statement, 
* and the Number of Sets to the number of fields we are transfering
* (There is a limitation of 6000 total Points * Sets in the Graph Object.)
Graph1.NumPoints = RecCount()
Graph1.NumSets = 3

* Tell the Graph Control Object what Type of Graph we are displaying, a line graph
Graph1.GraphType = 6

* Set Record, and Array pointers for Graphics Server to use
I = 0
Go Top
Do while .not. eof()
	I = I + 1
	* Tell Graphics Server to use Set 1 for Field 1.  As
	* you can see, the Point is set by the Index to the Array Property.
	Graph1.ThisSet = 1
	Graph1.Data(I) = Field1
	Graph1.ThisSet = 2
	Graph1.Data(I) = Field2
	Graph1.ThisSet = 3
	Graph1.Data(I) = Field3
	Skip
EndDo
* Tell Graphics Server to update the graph with the new settings
* {Without this, The graph will NOT update}
Graph1.DrawMode = 2

*Code from within the Second Command Button
* This command button shows how to move my data from the Database
* to Graphics Server's .GraphData Property
* First, Set the veriable Graph1 to the Graph object from the Form
Graph1 = ThisForm.OleControl1

* Set the Number of Points to the number of records from the SQL Statement, 
* and the Number of Sets to the number of fields we are transfering
* (There is a limitation of 6000 total Points * Sets in the Graph Object.)
Graph1.NumPoints = RecCount()
Graph1.NumSets = 3

* Tell the Graph Control Object what Type of Graph we are displaying
Graph1.GraphType = 6
* Tell the Graph Control Object that we will manually increment the
* values of ThisPoint and ThisSet
Graph1.AutoInc = 0

* Set Record, and Array pointers for Graphics Server to use
I = 0
Go Top
Do while .not. eof()
	I = I + 1
	* Tell Graphics Server to use Set 1 for Field 1.  As
	* you can see, This differs from the Array property in 
	* That the index is set via the ThisPoint property.
	Graph1.ThisSet = 1
	Graph1.ThisPoint = I
	Graph1.GraphData = Field1
	Graph1.ThisSet = 2
	Graph1.ThisPoint = I
	Graph1.GraphData = Field2
	Graph1.ThisSet = 3
	Graph1.ThisPoint = I
	Graph1.GraphData = Field3
	Skip
EndDo
* Tell Graphics Server to update the graph with the new settings
* {Without this, The graph will NOT update}
Graph1.DrawMode = 2


*****************************************************************************
Host Language: Visual FoxPro
Product: Graphics Server
Version Number: 4.0x

Key-Words: INSTALLATION FOXPRO OCX
Issue:
How is a Graphics Server (version 4.0x) graph control added to a Visual FoxPro application?
Short Answer:
It is added as an OLE container control.
Discussion:
Adding a graph control to a Visual FoxPro project

This assumes that you have already installed Graphics Server and the 32-bit graphics server OCX, and GRAPHX32.OCX is registered. If you have any problems with these steps, please read the document OCXHELP.WRI, or obtain document GSKB001 from the Technical Support Knowledge Base.

This bulletin also gives the steps for creating a new form and adding the control. If you are working with an existing form, omit the unnecessary steps.

Create a new project. From the File menu, pick "New", then in the dialog box, click the option button for project, and click the icon for "New File".

You will be presented with a Project Manager dialog box. Click the "Documents" tab, then select "Forms" and click the "New" button. This will present you with a choice of "Form Wizard" or "New Form." Click "New Form."

You should now have a blank form and the toolbox. Select an OLE Container Control, and drag out a region on your form. This will bring up the "Insert Object" dialog box. Select the "Insert Control" option button. This will bring up a list of available controls, which should include "BPS Extended Graph Control."

If "BPS Extended Graph Control" is not listed, you will need to click "Add Control..." and browse for \windows\system\graphx32.ocx. Do not use graph32.ocx -- this is a smaller, less-featured version of the OCX.

Select "BPS Extended Graph Control" and click "OK". This will place a graph control (default type of 3D bars) on your form. You can now change all of its properties at design time by right-clicking on the control and using the properties pages, or by changing the properties in the form's properties window.

The graph can also be changed at runtime as described in "The Graph Control" and "The Graph Library" manuals. The following code is a minimal example of how to change the graph just through the properties of the OCX. It can be attached to a command button as a test of whether your Graphics Server OCX is working correctly.

Example Code:
 
thisform.graph1.background = 14  && yellow background
thisform.graph1.numsets = 2      && 2 sets
thisform.graph1.numpoints = 5    && 5 points
thisform.graph1.graphtype = 4    && 3D bar
thisform.graph1.graphstyle = 6   && Z-Clustered style
thisform.graph1.autoinc = 0      && do incrementing manually

thisform.graph1.backgrounduse = 6    && legend
thisform.graph1.backgroundstyle = 1  && border
thisform.graph1.graphtitle = "Test Title"

&& Loop through all sets, all points, assigning data values

for i = 1 to thisform.graph1.numsets
	thisform.graph1.thisset = i
	thisform.graph1.legend(i) = "Legend " + ltrim(str(i))
	for j = 1 to thisform.graph1.numpoints
		thisform.graph1.data(j) = 20 - (i * j)
	next
next

thisform.graph1.drawstyle = 1    && color (default)
ThisForm.Graph1.DrawMode = 2     && redraw on screen
&& thisform.graph1.printstyle = 3   && color with border
&& thisform.graph1.drawmode = 5     && send out to printer

******************************************************************************


Bulletin Number: GSKB044

Host Language: Visual FoxPro
Product: Graphics Server
Version Number: 4.0x

Key-Words: OCX FOCUS INIT CHANGES
Issue:
Problems with the OCX not painting when initilized
Short Answer:
Place a THISFORM.OLECONTROL.SetFocus line in your code
Discussion:
When the control is changed in the Init Event(), Graphics Server is not receiving focus to paint the information correctly, and may show an Empty control untill another event requires a Paint. By placing a THISFORM.OLECONTROL.SetFocus line in your code, you will trigger a Paint event. This is also required to trigger any properties changed in the Init event.


******************************************************************************
Host Language: FoxPro
Product: Graphics Server
Version Number: 4.0x

Key-Words: AG OVERLAY
Issue:
How do I Overlay with AutoGraph
Short Answer:
Try the sample code below:
Discussion:
Example Code:
*:*****************************************************************************
*:
*:        Program: AGOVLY.PRG
*:         System: Graphics Server Demo
*:      Copyright (c) March 1996, Pinnacle Publishing Inc.
*:  Last modified: 03/13/96 at 08:00:00
*:
*:
*:*****************************************************************************
keynum=0
SET LIBRARY TO ..\lib\gswapi.fll
SET MESSAGE TO "hit ESCape to exit"
DIMENSION amparray(10,3),colours(3),labels(10),legends(3), patt(3), aux(10,3)
r=RAND(-1)
FOR i=1 TO 10
   If I = 3
      amparray(i,1) = 0
   Else
      amparray(i,1)=RAND()*100
   EndIf
   If I = 7
      amparray(i,2)=0
   Else
      amparray(i,2)=RAND()*100
   EndIf
   &&array(i,3)=RAND()*10000
   If I = 5
      amparray(i,3)=0
   Else
      amparray(i,3)=(Log( I * 10)/Log(10))
   EndIf
   For J = 1 to 3
      If amparray(i,j) = 0
         aux(i,j) = 256
      Else
         aux(i,j) = 0
      EndIf
   Next
NEXT ( i )
&&aux(5,3) = 256
patt(1) = 3
patt(2) = 2
patt(3) = 2

colours(1)=5
colours(2)=8
colours(3)=9
labels(1)="first"
labels(2)="second"
labels(3)="third"
labels(4)="fourth"
labels(5)="fifth"
labels(6)="sixth"
labels(7)="seventh"
labels(8)="eighth"
labels(9)="nineth"
labels(10)="tenth"
legends(1)="group 1"
legends(2)="group 2"
legends(3)="OVERLAY"
DEFINE WINDOW dummy FROM 1,1 TO SROWS() - 1,SCOLS() - 1
ACTIVATE WINDOW dummy
r=GSOpenServer("","c")
r=AGOpen()
wid=GSGetAXExt("dummy")
ht=GSGetAYExt("dummy")
W=GSOpenChildWin("dummy",0,0,wid,ht,1000,1024+2048,3,"gs window")
r=AGAmp(10,3,@amparray(1,1))      && send data
r=AGAux(10*3,@aux(1,1))
r=AGClr(3,@colours(1))           && send colours
r=AGPatt(3,@patt(1))             && Set patterns for the lines
r=AGLabels(10,@labels(1))         && labels
r=AGLegend(3,@legends(1))        && legends
r=AGTitleg("Graphics Server Overlay Graph" + chr(10) +;
              "That will NOT plot Zero")
r=AGFontStyle(0,2,32+16,0)       && choose fonts
r=AGFontStyle(2,2,0,0)
r=AGFontStyle(3,2,32,0)
r=AGShow(6 + 256 + 512, 8192 + 16384, 1)
r=AGShow(6, 4096 + 16 + 16384, 1)
F=.T.
DO WHILE F                      && loop until escape is pressed
   STORE INKEY(0,"MH") TO keynum
   IF keynum=27
      F=.F.
   ENDIF ( keynum=27 )
   If UPPER(CHR(keynum)) = "C"
      r=GSClipWrite(0,0,0,0,2,0)     && copies the graph to the clipboard
   EndIf
ENDDO
r=GSCloseWin(W)                  && close the window
RELEASE WINDOW dummy
RELEASE WINDOW output
A=AGClose()                     && close down and tidy up
A=GSCloseServer()
SET MESSAGE TO
SET LIBR TO
*: EOF: AGOVLY.PRG


*****************************************************************************
Host Language: Visual FoxPro
Product: Graphics Server
Version Number: 4.x, 5.x

Key-Words: PRINTINFO PRINTER HDC API
Issue:
How can I use the PrintInfo properties in Visual FoxPro?
Short Answer:
You'll need to get the printer's hDC via Windows API functions.
Discussion:
The code below assumes that you've already created a graph to your liking using the Graphics Server 32-bit OCX. It sets the page to be 100x100 logical units. You can change this if you need a finer degree of control over the size. It has been tested under Windows 95 using Visual FoxPro 3.0 and Graphics Server versions 4.04 and 4.50. A sample project using this code is available from our FTP site ftp://graphicsserver.com/GServer/SampleCode/FOXPINFO.ZIP.

Begin code:
 
* Subroutine: CmdGraphPrint
* Purpose: Print a Graphics Server OCX using the PrintInfo property
*          under Visual FoxPro
* Code courtesy of: James R. McLaughlin, Softronics Inc.
* Creation Date: 07/17/96
*
* Notes: The main problem with printing the OCX from Visual FoxPro
* is that a printer hDC is needed. James McLaughlin has written
* code in the 32-bit Windows API which retrieves the printer's
* device context, allowing PrintInfo to be used to control the size
* and position of a graph.
*
* If you have questions on this code, PLEASE DO NOT attempt to
* contact Mr. McLaughlin; he is not an employee of Pinnacle Publishing,
* and has provided this code as a courtesy to us and our customers.

LOCAL lcBuffer, lnNumBytes, lcPrinterEnd, lcDeviceEnd
LOCAL lcPrinter, lcDevice, lcOutput, lnhDC, lcDocName
LOCAL loGraph

#DEFINE STARTDOC 10
#DEFINE NEWFRAME 1
#DEFINE ENDDOC 11

*-- DECLARE DLL statements
DECLARE INTEGER GetProfileString IN Win32API ;
	String cSection, String cKey, String cDefault, ;
	String @cBuffer, Integer nBufferSize
	
DECLARE INTEGER CreateDC IN Win32API ;
	String cDriver, String cDevice, String cOutput, String @cInitData
	
DECLARE INTEGER DeleteDC IN Win32API ;
	Integer nDC
	
DECLARE INTEGER Escape IN Win32API ;
	Integer nDC, Integer nEscape, Integer nInput, ;
	String @cInData, String cOutData
	
lcBuffer = SPACE(255) + CHR(0)
lnNumBytes = GetProfileString("windows", "device", "", ;
                              @lcBuffer, LEN(lcBuffer))
lcPrinterEnd = AT(",",lcBuffer)
lcDeviceEnd = AT(",",lcBuffer,2)
IF lnNumBytes<=0 OR lcPrinterEnd = 0 OR lcDeviceEnd=0
	=MsgStop("Unable to retrieve printer profile string")
	RETURN
ELSE
	lcPrinter = SUBSTR(lcBuffer,1,lcPrinterEnd-1)
	lcDevice = SUBSTR(lcBuffer,lcPrinterEnd+1,lcDeviceEnd-lcPrinterEnd-1)
	lcOutput = SUBSTR(lcBuffer,lcDeviceEnd+1)
ENDIF

lnhDC = CreateDC(lcDevice, lcPrinter, lcOutput, .NULL.)
IF lnhDC<=0
	=MsgStop("Unable to create device context")
	RETURN
ENDIF

lcDocName = "Print Test"
IF Escape(lnhDC, STARTDOC, LEN(lcDocName), @lcDocName, .NULL.) <= 0
	WAIT WINDOW "Unable to start document"
ELSE
	loGraph = thisform.Graph1
	loGraph.PrintInfo(1) = lnhDC
	loGraph.PrintInfo(6) = 0		&& set origin to 0
	loGraph.PrintInfo(7) = 0		&& set origin to 0
	loGraph.PrintInfo(8) = 100		&& set paper to 100 units wide
	loGraph.PrintInfo(9) = 100		&& set paper to 100 units long
	loGraph.PrintInfo(2) = 5		&& set up a 5% left margin
	loGraph.PrintInfo(3) = 20		

Category ActiveXControls Category Code Samples
( Topic last updated: 2000.03.28 09:36:45 PM )