Page 1 of 1

[Solved] Data Labels in Pie Chart

Posted: Tue Oct 04, 2011 5:30 pm
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

Re: Data Labels in Pie Chart

Posted: Tue Oct 04, 2011 10:32 pm
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

Re: Data Labels in Pie Chart

Posted: Wed Oct 05, 2011 2:54 am
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.

Re: Data Labels in Pie Chart

Posted: Wed Oct 05, 2011 2:55 am
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

Re: Data Labels in Pie Chart

Posted: Wed Oct 05, 2011 7:39 am
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

Re: [Solved] Data Labels in Pie Chart

Posted: Fri Nov 09, 2012 8:19 am
by vjlk16
I am using vbscript and I get error "object required" at the following line.
Set oObj_3 = oCoordinateSystems(0)

Re: [Solved] Data Labels in Pie Chart

Posted: Fri Nov 09, 2012 9:40 am
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

Re: [Solved] Data Labels in Pie Chart

Posted: Mon Nov 26, 2012 7:07 am
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