Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Sample of MS Graph? VFP5/6
Message
De
22/09/1999 05:16:34
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
21/09/1999 12:39:04
Information générale
Forum:
Visual FoxPro
Catégorie:
Contrôles ActiveX en VFP
Divers
Thread ID:
00267187
Message ID:
00267484
Vues:
22
>Does anyone have a sample of using an MS Graph object embedded in a form -- especially how to set its datasheet from a cursor or array, and how to change graph types on the fly?
>
>I want this graph to be part of a bigger form, not its own thing.
>
>Help is as always, gratefully accepted.
>
>The sample in VFP6 help is woefully underdocumented, and the GRAPH object is useless; it only calls a wizard to build a GRAPH OLE object, but without showing how to do it.
>
>-- jas


Jeff,
Below sample also includes a reporting. Hope helps (Datatable slows down the plotting and update) :
*!*	Below example is for Graph8. (Nearly same as Excel charting)
*!* If you cannot download wc0993.exe from microsoft site or UT
*!*	xlConstants can be found by :
*!*	-Open Excel
*!*	-Select tools\macro\VB editor
*!*	-Press F2 to bring up "Object browser"
*!*	-Find needed xlConstant type ie:xlChartType
*!*	-On right window click needed Constant ie: xl3DArea
*!*	-Below the window constant value is displayed
*!* cetin@imst.deu.edu.tr

*** set the LOCALEID to English
nlLocaleId=sys(3004)		&& Save local id
=sys(3006,1033)				&& We will be sending instructions in English

* Part of xlChartType constants
#Define xl3DArea 					-4098
#Define xl3DColumn					-4100
#Define xl3DLine					-4101
#Define xl3DPie						-4102
#Define xlArea						1
#Define xlBubble3DEffect			87
#Define xlLine						4
#Define xlPie						5
#Define xlRadar						-4151
#Define xlSurface					83

#Define TAB CHR(9)
#Define CRLF CHR(13)+CHR(10)


Create cursor test (degree i, sine n(8,4) NULL, cosine n(8,4))
For ix = 1 to 90
  Insert into test ;
    values ;
    (ix,cos(ix)*ix,sin(ix)*ix)
Endfor
45
Scan next 30     && Nullify 30 degrees
  Replace sine with .null.       && Nullify some values to see effect
Endscan

Wait window nowait "Filling cell values..."
MCGDATA = ""
nCols = fcount()
For ix = 1 to nCols
  MCGDATA = MCGDATA + iif(empty(MCGDATA),"",TAB)+field(ix)
Endfor
MCGDATA = MCGDATA + CRLF
Scan
  For ix = 1 to nCols
    MCGDATA = MCGDATA + iif(ix=1,"",TAB)+nvl(str(evaluate(field(ix))),"")
  Endfor
  MCGDATA = MCGDATA + CRLF
Endscan
* Data prepare *

Create cursor testgen (graphtest g)
Append blank
Append general graphtest class "MSGraph.Chart" data MCGDATA
Create report testgraph from testgen
Messagebox("Now you'll see a report designer window."+chr(13)+;
  "Pls add an OLEBoundControl and size big enough." ;
  +chr(13)+"Use [graphtest] as fieldname")
Modi report testgraph
***
* Now we have Graph object in gen field. (Graph8)
* Play with it

oForm = createobject("Form")
With oForm
  .height = 400
  .width = 600
  .show
  .closable = .f.
  .addobject("myGraph","OleBoundControl")
  .addobject("myQuit1","myQuit")
  .addobject("myChanger1","myDataChanger")
  .addobject("myChanger2","myTypeChanger")
  .addobject("myReport1","myReport")
  With .myGraph
    .height = oForm.height - 20
    .width = oForm.width
    .left = 0
    .top = 0
    .ControlSource = "testgen.graphtest"


    Wait window nowait "Plotting..."
    .hastitle = .t.
    .haslegend = .t.
    .ChartTitle.caption = "This is chart title"
    .ChartType=xl3DArea
    .object.application.plotby = 2
    #Define xlCategory		1
    #Define xlValue			2
    #Define xlSeriesAxis	3
    With .Axes(xlCategory)
      .hastitle = .t.
      With .AxisTitle
        .Caption = "This is category title"
        .Font.Name = "Arial"
        .Font.Size = 10
        .Font.Bold = .t.
      Endwith
    Endwith
    With .Axes(xlSeriesAxis)
      .hastitle = .T.
      With .AxisTitle
        .Caption = "This is SeriesAxis title"
        .Font.Size = 8
        .Font.Bold = .f.
        .Orientation = 90 && Show 90 degrees rotated
      Endwith
    Endwith
    With .Axes(xlValue)
      .hastitle = .T.
      With .AxisTitle
        .Caption = "This is Value title"
        .Font.Size = 10
        .Font.Bold = .f.
        .Orientation = 90 && Show 90 degrees rotated - clockwise
      Endwith
    Endwith
    .hasdatatable = .t.
    .DataTable.HasBorderOutline = .T.
    With .DataTable.font
      .name = "Arial"
      .size = 8
    Endwith
    Wait clear
    .ChartArea.copy()
    .visible=.T.
  Endwith
  .myQuit1.visible = .t.
  .myReport1.left = .myChanger2.left+.myChanger2.width + 5
  .myReport1.visible = .t.
  .myChanger1.visible = .t.
  .myChanger2.visible = .t.
Endwith
**** Set the LocaleId to the previous value
=sys(3006,val(nlLocaleId))

Read events

Define class myquit as commandbutton
  Left=1
  Top=0
  AutoSize = .T.
  Caption="Close"
  Procedure click
  Release all
  Clear events
Endproc
Enddefine

Define class myDataChanger as commandbutton
  Left=150
  Top=0
  AutoSize = .T.
  Caption="Change some data"
  Procedure click
  Wait window nowait "Changing cell values..."
  With thisform.myGraph
    .hasdatatable = .f. && Temporarily turn ity off
    With .object.application.datasheet
      Select test
      Scan
        If isnull(sine)
          .Cells(recno()+1,2).Value = sin(recno())*recno()
        Endif
      Endscan
    Endwith
    .hasdatatable = .t.
  Endwith
  Select testgen
  Thisform.myGraph.doverb(-6)
  Wait clear
Endproc
Enddefine

Define class myTypeChanger as commandbutton
  Left=300
  Top=0
  AutoSize = .T.
  Caption="Change Chart Type"
  Procedure click
  Thisform.myGraph.ChartType = xlBubble3DEffect
  Thisform.myGraph.doverb(-6)
Endproc
Enddefine

Define class myreport as commandbutton
  Left=1
  Top=0
  AutoSize = .T.
  Caption="Report"
  Procedure click
* warning !!! - Testgraph prepared manually containing gen field and sized
  Messagebox("If you changed graphtype click once to update."+chr(13)+"This is a quirk of MSGraph.")
  Report form testgraph preview
Endproc
Enddefine
But actually I suggest using Excel if possible, which is more stable, faster and rich.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform