Page 1 of 1

[Solved] Set programmatically values and labels of a chart

Posted: Tue Oct 20, 2015 6:45 pm
by RufusWein
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

	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.

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

Posted: Tue Oct 20, 2015 8:54 pm
by Villeroy
[Tutorial] Introduction into object inspection with MRI
install MRI.

Add this to your Basic code:

Code: Select all

GlobalScope.BasicLibraries.loadLibrary("MRILib")
mri objChart

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

Posted: Tue Oct 20, 2015 10:22 pm
by MTP
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

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

Posted: Wed Oct 21, 2015 1:38 pm
by RufusWein
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

   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