General information
Category:
COM/DCOM and OLE Automation
Cetin,
Thanks very much for your reply.
The sample code you included is very different from the code I am working with and I am having a hard time determining how to do the same thing in my code. Perhaps if you see the code I am using, you will be able to show me where and how it can be done.
Lparameters lcCursor, lcGraphField, lcYAxisLabel, lcXAxisLabel
* create the Excel spreadsheet
loXL = Createobject('Excel.Application')
loWB = loXL.Workbooks.Add()
With loWB.ActiveSheet
.Name = 'BudgetData'
lnFldCount = Fcount((lcCursor))
lnRecCnt = Reccount((lcCursor)) + 1
Select &lcCursor
Go Top
_vfp.DataToClip((lcCursor),Reccount((lcCursor)),3)
lcCell = 'A1:' + Chr(64 + lnFldCount) + Transform(lnRecCnt)
.Paste(.Range(lcCell))
.Range('A1').Value = ''
Do Case
Case lcCursor = 'cCustomers'
.Range('B1').Value = '' && 'PPMs'
Case lcCursor = 'cCustomers2'
.Range('B1').Value = '' && 'Defect Categories'
Endcase
Go Top In (lcCursor)
Endwith
* loXL.Visible = .T. && for testing only
* create the graph
loChart = loWB.Charts.Add()
lnPlotBy = xlColumns && xlRows
With loChart
.SetSourceData(loWB.Sheets('BudgetData').Range(lcCell),lnPlotBy)
.ChartType = 51 && xlBar && 2
.PlotArea.Interior.Color = Rgb(255,255,255)
* save graph to a temporary file
lcFileName = Sys(2015)+'.xls'
.SaveAs(Fullpath(Curdir()) + lcFileName)
Endwith
* quit Excel
loXL.Quit()
* insert graph into cursor
Select coGraphs
Append General (lcGraphField) From (lcFileName) Class 'Excel.Chart'
Tableupdate(.T., .T., 'coGraphs')
Erase (lcFileName)
With Thisform
.oGraph.ControlSource = (lcGraphField)
.oGraph.Visible = .F. && .T.
.LockScreen = .F.
.oGraph.Refresh()
Endwith
Local lnAxisId, lnCnt
With Thisform.oGraph.Object.ActiveChart
*FOR lnSeries = 1 TO lnTopParts
* .SeriesCollection[lnSeries].HasDataLabels = .T. && this works
* .SeriesCollection[lnSeries].DataLabels.Font.Name = 'Times New Roman'
* .SeriesCollection[lnSeries].DataLabels.Font.Size = 6 && this does not reduce the label font size - why ???
*ENDFOR
.SeriesCollection[1].HasDataLabels = .T.
*.SeriesCollection[1].DataLabels.Font.Size = .SeriesCollection[1].DataLabels.Font.Size - 4 && does not work
.ChartArea.Font.Name = 'Times New Roman'
.ChartArea.Font.Bold = .T.
*****.PlotArea.Interior.Width = 50
.HasTitle = .T.
.HasLegend = .F.
.ChartTitle.Font.Name = 'Times New Roman'
.ChartTitle.Font.Bold = .F. && .T.
.ChartTitle.Text = lcYAxisLabel
.ChartTitle.Font.Size = 14
*** if this is a pie graph, there is no way
*** to check to see if we have an Axis. Any attempt
*** to check the chart's HasAxis property or .Axes.Count property
*** results in a OLE exception
If Not Inlist( .ChartType, xl3DPie, xlPie, xlPieOfPie, xlPieExploded, xl3DPieExploded, xlBarOfPie )
*** Now set the axes at right angles for 3-d bar, column, and line charts
If Inlist( .ChartType, xl3DColumnClustered, xl3DColumnStacked, xl3DColumnStacked100, xl3DBarClustered, xl3DBarStacked, xl3DBarStacked100, xl3DLine )
.RightAngleAxes = .T.
Endif
*.Legend.Font.Size = 12 && 18 && removed 06/30/2003
With .Axes( xlCategory )
.TickLabels.Font.Size = 9 && 14
lcTitleText = lcXAxisLabel
If Not Empty( lcTitleText )
.HasTitle = .T.
.AxisTitle.Text = lcTitleText
Do Case
Case lcCursor = 'cCustomers'
.AxisTitle.Font.Size = 14
Case lcCursor = 'cCustomers2'
.AxisTitle.Font.Size = 14
Case lcCursor = 'cCustomers3'
.AxisTitle.Font.Size = 14
Case lcCursor = 'cCustomers4'
.AxisTitle.Font.Size = 14
Endcase
Else
.HasTitle = .F.
Endif
Endwith
With .Axes( xlValue )
.TickLabels.Font.Size = 12
*lcTitleText = ALLTRIM( Queries.cTitleY )
lcTitleText = lcYAxisLabel
If Not Empty( lcTitleText )
.HasTitle = .T.
.AxisTitle.Text = lcTitleText
.AxisTitle.Font.Size = 12 && 16
Else
.HasTitle = .F.
Endif
Endwith
*Wait window '.Axes.Count = ' + Str(.Axes.Count,2)
If .Axes.Count > 2
With .Axes( xlSeriesAxis )
.TickLabels.Font.Size = 8
*lcTitleText = ALLTRIM( Queries.cTitleZ )
lcTitleText = '????'
If Not Empty( lcTitleText )
.HasTitle = .T.
.AxisTitle.Text = lcTitleText
.AxisTitle.Font.Size = 10
Else
.HasTitle = .F.
Endif
Endwith
Endif
Else
*** Then we want to set things differently
*** Because pie charts don't have axes
.HasTitle = .T.
.ChartTitle.Text = 'XXXXX' && ALLTRIM( EVALUATE( 'CsrResults.' + FIELD( 1, 'csrResults' ) ) )
.ChartTitle.Font.Size = 12
.Legend.Font.Size = 10
.ApplyDataLabels()
.SeriesCollection( 1 ).Datalabels.Font.Size = 8
Endif
Endwith
Tableupdate(.T., .T., 'coGraphs')
*** And refresh the control
With Thisform.oGraph
.Visible = .F. && .T.
.Refresh()
Endwith
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only