[Solved] Set programmatically values and labels of a chart

Creating a macro - Writing a Script - Using the API

[Solved] Set programmatically values and labels of a chart

Postby RufusWein » Tue Oct 20, 2015 6:45 pm

Hi, here again. I have learned to set values to the chart programmatically using an array(random), but not how to set the labels enumerated(change name).
For example:

Code: Select all   Expand viewCollapse view
   Dim charts As Object : charts = sheet.Charts
   Dim chart as Object  : chart  = charts.getByIndex(0).EmbeddedObject
   
   Dim data : data = chart.getData(0)
...
...   
   data.setData(DataArray)


One possibility that I ponder, is if this can't be done programmatically using an array, would use the range cells system only because I appreciate that using an array of data disable the range cells and the change to data table editor. It seems that does not allow a hybrid system.
Last edited by RufusWein on Wed Oct 21, 2015 1:39 pm, edited 1 time in total.
Apache OpenOffice 4.1.1 on Windows 8
RufusWein
 
Posts: 4
Joined: Sun Oct 18, 2015 5:15 pm

Re: How set programmatically the values and labels of a char

Postby Villeroy » Tue Oct 20, 2015 8:54 pm

[Tutorial] Introduction into object inspection with MRI
install MRI.

Add this to your Basic code:
Code: Select all   Expand viewCollapse view
GlobalScope.BasicLibraries.loadLibrary("MRILib")
mri objChart
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28431
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How set programmatically the values and labels of a char

Postby MTP » Tue Oct 20, 2015 10:22 pm

Not sure if you've come across them but the code examples by hanya have helped me in the past when I've used macros on charts: Re: Add multiple series in calc chart using macros or maybe Re: Custom data labels on my OOo charts. I modified it some to work on a bar chart in [Solved] .setModified(False) not working after chart mod
OpenOffice 4.1.1 on Windows 10, HSQLDB 1.8 split database
User avatar
MTP
Volunteer
 
Posts: 1620
Joined: Mon Sep 10, 2012 7:31 pm
Location: Midwest USA

[Solved] How set programmatically the values and labels of a

Postby RufusWein » Wed Oct 21, 2015 1:38 pm

Ok, thank very much, specially to VilleRoy for recommending the MRI tool which is great useful for locating methods or functions of certain classes.

The function key that I was looking for is setRowDescriptions(). This function take a string array which contain the name or values of labels for the row of chart, X axis (for Y Axis labels use setColumnDescriptions())

Applying the previous example:

Code: Select all   Expand viewCollapse view
   Dim charts As Object : charts = sheet.Charts
   Dim chart as Object  : chart  = charts.getByIndex(0).EmbeddedObject
   
   Dim data : data = chart.getData(0)
...
...   
   data.setData(dataArray) ' set values of chart , for example Array(Array(1,2,3,4,5),Array(10,20,30,40,50))
   data.setRowDescriptions(LabelArray) ' set label of chart (row), for example Array("A","B","C","D","E")

...


Greetings and until other, bye
Apache OpenOffice 4.1.1 on Windows 8
RufusWein
 
Posts: 4
Joined: Sun Oct 18, 2015 5:15 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 3 guests