[Solved] Data Labels in Pie Chart

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
pu8y
Posts: 19
Joined: Wed Nov 17, 2010 6:56 am

[Solved] Data Labels in Pie Chart

Post by pu8y »

Hi all,

I am creating a simple pie chart from my VB program. This chart need to have all the value, percentage and category name as it's Data Labels. For a clearer picture I have attached the sample of chart.

However, the solution I have is not 100% meet with my requirements, which i can only set the DataCaption of each DataPoint to either 1, 2, or 4 (value, percentage or category). I hope to have ALL the value, percentage and category.

Code: Select all

Set aPointProp1 = oDiagram.getDataPointProperties(0, 0)
aPointProp1.DataCaption = 2
Set aPointProp2 = oDiagram.getDataPointProperties(1, 0)
aPointProp2.DataCaption = 2
I have read through this forum and finally i can conclude maybe I have to use DataPointLabel to achieve my requirements. I still have some errors which I cannot solve and not sure what is going wrong.

Code: Select all

Set oDiagram = chart.getDiagram
Set oFirstDiagram = chart.getFirstDiagram()
oCoordinateSystems = oFirstDiagram.getCoordinateSystems()
Set oObj_3 = oCoordinateSystems(0)
               
oChartTypes = oObj_3.getChartTypes()
Set oObj_4 = oChartTypes(0)
oDataSeries = oObj_4.getDataSeries()
Set oobj_5 = oDataSeries(0)
               
Set aLabel = oobj_5.getDataPointByIndex(0).getPropertyValue("Label")

aLabel.ShowNumberInPercent = True
aLabel.ShowCategoryName = True
There are error occur at code "Set aLabel = oobj_5.getDataPointByIndex(0).getPropertyValue("Label")" and hence it cannot proceed to set the chart with percentage and category name. :(
Any helping hands are greatly appreciated!

reference: http://api.openoffice.org/docs/common/r ... Label.html
Attachments
1.JPG
Last edited by pu8y on Wed Oct 05, 2011 7:41 am, edited 2 times in total.
OpenOffice 3.1 on Windows XP
ms777
Volunteer
Posts: 207
Joined: Mon Oct 08, 2007 1:33 am

Re: Data Labels in Pie Chart

Post by ms777 »

I cannot reproduce this. This OOBasic code works for me

Code: Select all

Sub Main
oChartShape = ThisComponent.Drawpages.getByIndex(0).getByIndex(0)
oChartModel = oChartShape.EmbeddedObject.Component
oDataSeries = oChartModel.FirstDiagram.CoordinateSystems(0).ChartTypes(0).DataSeries(0)

Dim oLabelAll as new com.sun.star.chart2.DataPointLabel
oLabelAll.ShowCategoryName = True   
oLabelAll.ShowLegendSymbol = False   
oLabelAll.ShowNumber       = True   
oLabelAll.ShowNumberInPercent = True   

Dim oLabelNumberOnly as new com.sun.star.chart2.DataPointLabel
oLabelNumberOnly.ShowCategoryName = False   
oLabelNumberOnly.ShowLegendSymbol = False   
oLabelNumberOnly.ShowNumber       = True   
oLabelNumberOnly.ShowNumberInPercent = False

' this sets it for the whole series. At least for those points, which have not yet been touched separately
oDataSeries.Label = oLabelAll
' this sets it for the a single data point
oDataSeries.getDataPointByIndex(0).Label = oLabelNumberOnly
End Sub
Good luck,

ms777
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Data Labels in Pie Chart

Post by hanya »

It seems this problem cased by the object implementation and the binding. The getPropertyValue method of the data point is not callable through the binding of OOo Basic. Try to use puseud-property way like ms777's code.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
pu8y
Posts: 19
Joined: Wed Nov 17, 2010 6:56 am

Re: Data Labels in Pie Chart

Post by pu8y »

Re-check again but still no luck to get it success.
I think I have wrong syntax in creating instance of DataPointLabel in VB, any idea?

Code: Select all

Set oSM = CreateObject("com.sun.star.ServiceManager")
Set oLabelAll = oSM.Createinstance("com.sun.star.chart2.DataPointLabel")
oLabelAll.ShowCategoryName = True
oLabelAll.ShowLegendSymbol = False
oLabelAll.ShowNumber = True
oLabelAll.ShowNumberInPercent = True
OpenOffice 3.1 on Windows XP
pu8y
Posts: 19
Joined: Wed Nov 17, 2010 6:56 am

Re: Data Labels in Pie Chart

Post by pu8y »

Hi All,

Finally I've found my solution. Should use GetStruct instead of create an instance.

Code: Select all

Set oLabelAll = oSM.Bridge_GetStruct("com.sun.star.chart2.DataPointLabel")
oLabelAll.ShowCategoryName = True
OpenOffice 3.1 on Windows XP
vjlk16
Posts: 2
Joined: Fri Nov 09, 2012 8:16 am

Re: [Solved] Data Labels in Pie Chart

Post by vjlk16 »

I am using vbscript and I get error "object required" at the following line.
Set oObj_3 = oCoordinateSystems(0)
openoffice 3, windows 7
User avatar
Charlie Young
Volunteer
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: [Solved] Data Labels in Pie Chart

Post by Charlie Young »

vjlk16 wrote:I am using vbscript and I get error "object required" at the following line.
Set oObj_3 = oCoordinateSystems(0)
Exactly what version of OpenOffice are you on? There were problems with 3.3.

viewtopic.php?f=44&t=38253
Apache OpenOffice 4.1.1
Windows XP
vjlk16
Posts: 2
Joined: Fri Nov 09, 2012 8:16 am

Re: [Solved] Data Labels in Pie Chart

Post by vjlk16 »

thanks for the reply.
i got the solution by using the following code:

Set oDiagram = oChart.getDiagram
Set aPointProp1 = oDiagram.getDataPointProperties(0, 0)
aPointProp1.DataCaption = 2
Set aPointProp2 = oDiagram.getDataPointProperties(1, 0)
aPointProp2.DataCaption = 2

for a 2 pieslice piechart
openoffice 3, windows 7
Post Reply