#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 EnddefineCetin