Thanks, I will try this
Daniel Rentz wrote:
Andrew Douglas Pitonyak schrieb:
How can I create an XY chart from a macro where each "Y" data value
has its own "X" data value. I know how to do this by hand because I
can individually specify these using the GUI. I can not, do this
using a macro.
Not sure if this is possible with the chart1 API, but it can be done
using the chart2 API. Following some hand-written untested (!) BASIC
code, that creates a new XY chart.
1) create or get a chart document
oChart = ...
2) let the Calc document create a data provider, set it at the chart
oDataProv = ThisComponent.createInstance(
"com.sun.star.chart2.data.DataProvider" )
oChart.attachDataProvider( oDataProv )
3) insert a diagram into the chart document
oDiagram = CreateUnoService( "com.sun.star.chart2.Diagram" )
oChart.setFirstDiagram( 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.$A$2:$A$6" )
oSequenceX.Role = "values-x"
oSequenceY = oDataProv.createDataSequenceByRangeRepresentation(
"$Sheet1.$B$2:$B$6" )
oSequenceY.Role = "values-y"
oSeriesTitle = oDataProv.createDataSequenceByRangeRepresentation(
"$Sheet1.$B$1" )
oSeriesTitle.Role = "label"
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() )
Hope this helps. Not sure if everything above is correct, so please
feel free to complain or ask ;-)
Daniel
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
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]