[Solved] Access dataseries from a chart

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
laulau59
Posts: 2
Joined: Wed Oct 26, 2016 10:08 am

[Solved] Access dataseries from a chart

Post by laulau59 »

Hi,

I'm trying to access the data in the data series of a chart with some oobasic coding.
Here is my piece of code :

Code: Select all

Dim oChart, oCharts As Object
Dim oDiagram as Object
Dim oData, oDataArray as Object
Dim DataSeries(0 To 11) as Double

oSheets = ThisComponent.Sheets
oCharts = oSheets(0).Charts
oChart = oCharts(0).EmbeddedObject
oDiagram = oChart.Diagram	
oData = oChart.getData()
'''XRay oData  
oDataArray = oData.Data
'''XRay oDataArray
DataSeries = oDataArray
'''XRay DataSeries

' loop below fails at i=0
For i=0 To 11
  print DataSeries(i)
Next
I cannot access the elements in array oDataArray, nor in array DataSeries (although Xray tells me they have the correct dimensions).

Any clue on this issue ?
Thanks.
Last edited by laulau59 on Wed Oct 26, 2016 11:28 pm, edited 1 time in total.
OpenOffice 4.1.3 - Linux x86_64
FJCC
Moderator
Posts: 9280
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Access dataseries from a chart

Post by FJCC »

DataSeries is an array of arrays. Try something like

Code: Select all

 print DataSeries(i)(0), DataSeries(i)(1) 
in your for-next loop
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
User avatar
Zizi64
Volunteer
Posts: 11362
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Access dataseries from a chart

Post by Zizi64 »

Here is an example file:
GetChartData.ods
(20.12 KiB) Downloaded 107 times
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
laulau59
Posts: 2
Joined: Wed Oct 26, 2016 10:08 am

Re: Access dataseries from a chart

Post by laulau59 »

Many thanks to both of you for the swift and efficient reply, got it.
OpenOffice 4.1.3 - Linux x86_64
Post Reply