Which properties of the pie chart are appropriate for setting from a macro to the items I listed in the Chart Wizard dialogs?

In the LibreOffice Calc book, a sheet with a data table in the range A1:U39 is created and a 3D pie chart is created in it at position V1 with the data range: H3:R3;H35:R35.
In the pie chart, I need to change the properties:

  • Chart subtitle set font to italic
  • Data series in rows - (true)
  • Data series in columns - (false)
  • Add data labels for all data series and in ‘Text Attributes’ set:
    ‘Values ​​as number’ - (false)
    ‘Values ​​as percentages’ - (true)
    ‘Category - (true)’,
  • In ‘Attribute Options’ set:
    Placement - (empty)
  • On tab ‘Font Effects’ in 'Text Decoration’set:
    Underlining -(Single)

Code snippet:

chart_name = “2023_03Pie”
range1 = oSheet.getCellRangeByName(“H3:R3”)
range2 = oSheet.getCellRangeByName(“H35:R35”)

RANGES = Array(range1.RangeAddress, range2.RangeAddress)
with rec
    .X = 47410
    .Y = 0         
    .Width = 29270
    .Height = 16430
end with

Charts.addNewByName(chart_name, rec, RANGES, True, True)	
oChart = charts.getByName(chart_name).EmbeddedObject
oChart.Diagram = oChart.createInstance("com.sun.star.chart.PieDiagram")
oChart.Title.String = "Discord articles"
oChart.Title.CharHeight = 20
oChart.SubTitle.String = "(in percentages)"
oChart.SubTitle.CharHeight =14
oChart.Diagram.Dim3D = True
oChart.DataSourceLabelsInFirstColumn  = False
oChart.HasLegend = True

==

This is for python but should give you some pointers.

See: Python LibreOffice Programming Charts Chapter 30. Bar, Pie, Area, Line Charts.
It has specific examples on modifying pie charts.

Also OOO Development Tools (OooDev) just added hunderds of classes for styling/formating various elements of LibreOffice, including charts.

The Documentation is in the works and current Chart docs for formatting can be seen in Chart2 Format Direct Series
In the meantime you can see the chart classed in the API Docs ooodev.format.chart2

1 Like