Drew Jensen wrote:
There is, however, a new service, that is not yet documented, that allows some more flexible changes, but I am having trouble figuring out exactly how that works. I can post some examples for that as well if you require them.



If you would Please Andrew...I would be interested.

Be warned, this is not documented, and it may change... Also, I was not able to get labels to work, but I did lose a few hours trying.


Sub UseChart2()

oSheet = ThisComponent.CurrentController.ActiveSheet
oGraphSheet=ThisComponent.getSheets().getByName("Sheet2")
' 1) create or get a chart document
oChart = oGraphSheet.getCharts().getByIndex( 0 )
oChartDoc = oChart.getEmbeddedObject()

'oChartDoc.HasLegend = False
'oChartDoc.DataSourceLabelsInFirstRow = False
'Inspect oChartDoc


'    2) let the Calc document create a data provider, set it at the chart
oDataProv = ThisComponent.createInstance( "com.sun.star.chart2.data.DataProvider" )
oChartDoc.attachDataProvider( oDataProv )
' 3) insert a diagram into the chart document

oDiagram = CreateUnoService( "com.sun.star.chart2.Diagram" )
oChartDoc.setFirstDiagram( oDiagram )
Inspect oDiagram

'    4) insert a coordinate system into the diagram

oCoordSys = CreateUnoService( "com.sun.star.chart2.CartesianCoordinateSystem2d" )
oDiagram.addCoordinateSystem( oCoordSys )

'    5) insert an XY chart type into the coordinate system

oChartType = CreateUnoService( "com.sun.star.chart2.ScatterChartType" )
oCoordSys.addChartType( oChartType )

'    7) insert a data series into the chart type

oSeries = CreateUnoService( "com.sun.star.chart2.DataSeries" )
oChartType.addDataSeries( oSeries )

'    8) let the data provider of Calc create data sequences from formulas:

oSequenceX = oDataProv.createDataSequenceByRangeRepresentation( "$Sheet1.$B$18:$B$52" )
oSequenceX.Role = "values-x"

oSequenceY = oDataProv.createDataSequenceByRangeRepresentation( "$Sheet1.$E$18:$E$52" )
oSequenceY.Role = "values-y"

oSeriesTitle = oDataProv.createDataSequenceByRangeRepresentation( "$Sheet1.$D$16" )
'This gives an error
'oSeriesTitle.Role = "label"
'Inspect oSeriesTitle

' 9) create labeled data sequences which combine the series title and series values:

oLabeledX = CreateUnoService( "com.sun.star.chart2.data.LabeledDataSequence" )
oLabeledX.setValues( oSequenceX )
' no title for X values

oLabeledY = CreateUnoService( "com.sun.star.chart2.data.LabeledDataSequence" )
oLabeledY.setValues( oSequenceY )
oLabeledY.setLabel( oSeriesTitle )

' 10) create an array from the labeled sequences (not sure about the correct BASIC syntax...), set it at the data series

Dim aSeqArray( 0 to 1 ) As Object
aSeqArray( 0 ) = oLabeledX
aSeqArray( 1 ) = oLabeledY
oSeries.setData( aSeqArray() )

End Sub


--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
My Book: http://www.hentzenwerke.com/catalog/oome.htm
Info:  http://www.pitonyak.org/oo.php
See Also: http://documentation.openoffice.org/HOW_TO/index.html


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to