I received a request on how to set the data on a chart. Calling setData
causes OOo to crash, and it used to work.
This appears to be a regression problem, because the macro used to work.
First, the original question as posed to me:
On 07/28/2009 11:11 AM, BD RJ wrote:
In OpenOffice.org Basic for Calc documents there was the method
*setData()* for charts, that made us able to assign chart's data from
an array.
We can find an example of code with this istruction in OpenOffice wiki
at the link:
http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Charts/Data_Access
Code lines in question are after the explanation of the
XChartDataArray interface.
We can analize this interface at the link:
http://api.openoffice.org/docs/common/ref/com/sun/star/chart/XChartDataArray.html
**
The method *setData() *belong to this inteface and his parameter and
description are in the last link.
The problem is:
In the last version of OpenOffice (OpenOffice 3.x) this istruction
make OpenOffice crash.
**
I have also explained my problem in
http://www.oooforum.org/forum/viewtopic.phtml?p=334655
but noone answered me.
Can you please help me?
Thanks in advance
The original macro that used to work is as follows:
Sub GR
oDoc = ThisComponent
oCurSheet = oDoc.CurrentController.ActiveSheet
oCharts = oCurSheet.Charts
Dim aRect as new com.sun.star.awt.Rectangle
oCharts.addNewByName("chart1", aRect, Array(), False, True)
oChart = oCharts.getByName("chart1").EmbeddedObject
Dim oData as Object
Dim oDataArray(0 To 1) as Object
Dim oX(0 To 2) As Double
Dim oY(0 To 2) As Double
oX(0) = 4.5
oX(1) = 2.6
oX(2) = 17.0
oY(0) = 45.0
oY(1) = 23.0
oY(2) = 11.0
oDataArray(0) = oX()
oDataArray(1) = oY()
oChart.Diagram.DataRowSource =
com.sun.star.chart.ChartDataRowSource.ROWS
oData = oChart.Data
oData.setData(oDataArray())
End sub
This fails when the data is set. I even tried a close approximation:
Sub GR
Dim oDoc, oCurSheet, oCharts, oChart
Dim oDiagram, oChartDoc
oDoc = ThisComponent
oCurSheet = oDoc.CurrentController.ActiveSheet
oCharts = oCurSheet.Charts
Dim oRect
' If (oCharts.hasByName("chart1")) Then
' Inspect oCharts
' Exit Sub
' End If
oRect = createObject("com.sun.star.awt.Rectangle")
oRect.X = 10000
oRect.Y = 1000
oRect.width = 10000
oRect.Height= 10000
oCharts.addNewByName("chart1", oRect, Array(), False, True)
oChart = oCharts.getByName("chart1")
Dim oData as Object
Dim oDataArray(0 To 1) as Object
Dim oX(0 To 2) As Double
Dim oY(0 To 2) As Double
oX(0) = 4.5
oX(1) = 2.6
oX(2) = 17.0
oY(0) = 45.0
oY(1) = 23.0
oY(2) = 11.0
oDataArray(0) = oX()
oDataArray(1) = oY()
oChartDoc = oChart.getEmbeddedObject()
oDiagram = oChartDoc.createInstance( "com.sun.star.chart.LineDiagram" )
oChartDoc.setDiagram( oDiagram )
oDiagram = oChartDoc.getDiagram()
oDiagram.DataRowSource = com.sun.star.chart.ChartDataRowSource.ROWS
oData = oChartDoc.Data
' Inspect oData
oData.setData(oDataArray())
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