Hi,
Thanks Daniel for providing the example! In fact the task can not be
done via the published chart API.
But when using chart2 API instead please keep in mind that it is not
published and is targeted for further changes. So the suggested code can
break in future versions.
So all, when spreading this example or otherwise chart2 API access
please also spread the knowledge that it uses unstable API and may not
work in future!
Thanks,
Ingrid
Andrew Douglas Pitonyak wrote:
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]