Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Interactive Pie Chart in Form
Message
From
20/08/2001 07:07:49
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
16/08/2001 12:58:04
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00544818
Message ID:
00546090
Views:
16
>Hi All:
>I know how to create a graph using the Graph wizard and field values that will save my chart to a general field. I also know how to display the chart from the general field into an OLE object on a form. Here's my question...does anyone have any code to create the chart in code. I need to be able to change the underlying field values on the form and then have the chart display the changes I've just made to the underlying field values. I'm assuming Visual Basic for Applications is the way to do it... I was kind of hoping that someone had developed an OCX that I could purchase. Anyone know where I can find a solution? Mark.

Mark,
With MSGraph you don't need any other OCX. Or you could use MSChart control as well. Here is a sample using MSGraph and changing values,type on form via code :
#Define xlCategory   1
#Define xlValue      2
#Define xlSeriesAxis 3

#Define xlTickLabelOrientationAutomatic  -4105
#Define xlTickLabelOrientationDownward  -4170
#Define xlTickLabelOrientationHorizontal  -4128
#Define xlTickLabelOrientationUpward  -4171
#Define xlTickLabelOrientationVertical  -4166

#Define xlColumnClustered 51
#Define xlBarClustered 57
#Define xl3DArea -4098
#Define xl3DColumn -4100
#Define xl3DLine -4101
#Define xl3DPie -4102
#Define xlArea 1
#Define xlLine 4
#Define xlPie 5
#Define xlRadar -4151

oForm = createobject('GraphForm')
oForm.Show
Read events

Define CLASS GraphForm AS form
  Top = 0
  Left = 0
  Height = 418
  Width = 655
  DoCreate = .T.
  Caption = "Form1"
  Name = "Form1"
  Add OBJECT mygraph AS oleboundcontrol WITH ;
    Top = 36, ;
    Left = 24, ;
    Height = 373, ;
    Width = 613, ;
    ControlSource = "testgen.graphtest", ;
    Name = "myGraph"
  Add OBJECT command1 AS commandbutton WITH ;
    Top = 3, ;
    Left = 553, ;
    Height = 27, ;
    Width = 84, ;
    Caption = "Exit", ;
    Name = "Command1"
  Add OBJECT command2 AS commandbutton WITH ;
    Top = 3, ;
    Left = 356, ;
    Height = 27, ;
    Width = 100, ;
    Caption = "Change cell data", ;
    Name = "Command2"
  Add OBJECT cmbtypes AS combobox WITH ;
    Height = 24, ;
    Left = 185, ;
    Top = 4, ;
    Width = 168, ;
    Name = "cmbTypes"
  Add OBJECT command4 AS commandbutton WITH ;
    Top = 3, ;
    Left = 23, ;
    Height = 27, ;
    Width = 84, ;
    Caption = "Plot By", ;
    Name = "Command4"
  Add OBJECT label1 AS label WITH ;
    Caption = "Chart Type", ;
    Height = 17, ;
    Left = 121, ;
    Top = 8, ;
    Width = 61, ;
    Name = "Label1"
  Add OBJECT command3 AS commandbutton WITH ;
    Top = 3, ;
    Left = 459, ;
    Height = 27, ;
    Width = 84, ;
    Caption = "Change data", ;
    Name = "Command3"
  Procedure _formataxes
  Lparameters taAxis, tnAxis
  With This.cmbtypes
    If tnAxis = 3 and .List(.Listindex) # '3D'
      Return
    Endif
  Endwith
  With this.mygraph
    If type(".Axes("+transform(tnAxis)+")") = "O"
      With .Axes(tnAxis)
        .hastitle = .t.
        With .AxisTitle
          .Caption = taAxis[1]
          .Orientation = taAxis[2]
          With .Font
            .Name = taAxis[3]
            .Size = taAxis[4]
            .Bold = taAxis[5]
            .Italic = taAxis[6]
            .Underline = taAxis[7]
          Endwith
        Endwith
      Endwith
    Endif
  Endwith
Endproc
  Procedure QueryUnLoad
  Clear events
Endproc
  Procedure Destroy
  =sys(3006,val(this.Tag))
Endproc
  Procedure Load
  This.tag=transform(sys(3004))	&& Save local id
  =sys(3006,1033)		&& We will be sending instructions in English
  Wait window nowait "Filling cell values..."

  Select a.country,sum(b.order_net) as 'Sales' ;
    from customer a ;
    inner join orders b on a.cust_id=b.cust_id ;
    group by country ;
    into cursor crsGraph

  lcTemp=sys(2105)+'.tmp'
  Copy to (lcTemp) type CSV
  lcData = chrtran(FileToStr(lcTemp),',',chr(9))
  Erase (lcTemp)

  Create cursor testgen (graphtest g)
  Append blank
  Append general graphtest class "MSGraph.Chart" data lcData
Endproc
  Procedure Init
  Wait window nowait "Plotting..."
  This.mygraph.doverb(-6)
  Dimension aCategoryAxis[7]
  aCategoryAxis[1] = "This is category title" && Title
  aCategoryAxis[2] = 0						&& Orientation
  aCategoryAxis[3] = "Arial"                  && Fontname
  aCategoryAxis[4] = 10                       && Fontsize
  aCategoryAxis[5] = .t.                      && Bold
  aCategoryAxis[6] = .f.						&& Italic
  aCategoryAxis[7] = .f.						&& Underline

  Dimension aSeriesAxis[7]
  aSeriesAxis[1] = "This is series title"
  aSeriesAxis[2] = 0
  aSeriesAxis[3] = "Arial"
  aSeriesAxis[4] = 8
  aSeriesAxis[5] = .t.
  aSeriesAxis[6] = .f.
  aSeriesAxis[7] = .f.

  Dimension aValueAxis[7]
  aValueAxis[1] = "This is Rotated Value title"
  aValueAxis[2] = 90
  aValueAxis[3] = "Times New Roman"
  aValueAxis[4] = 8
  aValueAxis[5] = .f.
  aValueAxis[6] = .f.
  aValueAxis[7] = .t.
  With Thisform
    With .mygraph
      .hastitle = .t.
      .ChartTitle.Text = "This is chart title"
      .ChartType = -4100 && 3Dcolumn
      If type(".Axes("+str(xlCategory)+")") = "O"
        With .Axes(xlCategory).TickLabels
          .Font.Size = 6
          .Orientation = xlTickLabelOrientationUpward
        Endwith
      Endif
      If type(".Axes("+str(xlValue)+")") = "O"
        .Axes(xlValue).TickLabels.Font.Size = 8
      Endif
      If type(".Axes("+str(xlSeriesAxis)+")") = "O"
        .Axes(xlSeriesAxis).TickLabels.Font.Size = 8
      Endif
      .Legend.Font.Size = 8
    Endwith
    ._formataxes(@aCategoryAxis,xlCategory)
    ._formataxes(@aSeriesAxis,xlSeriesAxis)
    ._formataxes(@aValueAxis, xlValue)
  Endwith
  Wait clear
Endproc
  Procedure command1.Click
  Clear events
  Thisform.release
Endproc
  Procedure command2.Click
  Wait window nowait "Changing cell values..."
  With thisform.mygraph.object.application.datasheet
    For ix=2 to 5
      .Cells(ix,2).Value = .Cells(ix,2).Value * 3
    Endfor
  Endwith
  Wait clear
Endproc
  Procedure cmbtypes.Init
  With this
    .Addlistitem('ColumnClustered',1,1)
    .Addlistitem(transform(xlColumnClustered),1,2)
    .Addlistitem('BarClustered',2,1)
    .Addlistitem(transform(xlBarClustered),2,2)
    .AddlistItem('3DLine',3,1)
    .AddlistItem(transform(xl3DLine),3,2)
    .AddlistItem('3DPie',4,1)
    .AddlistItem(transform(xl3DPie),4,2)
    .AddlistItem('Area',5,1)
    .AddlistItem(transform(xlArea),5,2)
    .Addlistitem('3DArea',6,1)
    .Addlistitem(transform(xl3DArea),6,2)
    .AddlistItem('Line',7,1)
    .AddlistItem(transform(xlLine),7,2)
    .AddlistItem('Pie',8,1)
    .AddlistItem(transform(xlPie),8,2)
    .AddlistItem('Radar',9,1)
    .AddlistItem(transform(xlRadar),9,2)
    .AddlistItem('3DColumn',10,1)
    .AddlistItem(transform(xl3DColumn),10,2)
    .Columncount = 2
    .Columnwidths = '120,50'
  Endwith
Endproc
  Procedure cmbtypes.InteractiveChange
  With thisform.mygraph
    .ChartType = val(this.List(this.Listindex,2))
    .Setfocus
  Endwith
  This.setfocus
Endproc
  Procedure command4.Click
  With thisform.mygraph.object.application
    .plotby = iif(.plotby=1,2,1)
  Endwith
Endproc
  Procedure command3.Click
  If thisform.Tag = 'count'
    Select a.country,sum(b.order_net) as 'Sales' ;
      from customer a ;
      inner join orders b on a.cust_id=b.cust_id ;
      group by country ;
      into cursor crsGraph
    Thisform.Tag = 'sum'
  Else
    Select country,cnt(*) as 'Count' ;
      from customer ;
      group by country ;
      into cursor crsGraph
    Thisform.Tag = 'count'
  Endif
  lcTemp=sys(2105)+'.tmp'
  Copy to (lcTemp) type CSV
  lcData = chrtran(FileToStr(lcTemp),',',chr(9))
  Erase (lcTemp)
  With thisform.mygraph
    .ControlSource = ''
    Select testgen
    Blank fields graphtest
    Append general graphtest class "MSGraph.Chart" data lcData
    .ControlSource = 'testgen.GraphTest'
  Endwith
  Thisform.Init
Endproc
Enddefine
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
Previous
Reply
Map
View

Click here to load this message in the networking platform