How to set up x axis major/minor values?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
onemorequestion
Posts: 3
Joined: Sat Dec 03, 2022 10:56 pm

How to set up x axis major/minor values?

Post by onemorequestion »

I try to manipulate the major interval values for x axis in a line diagram of type Date.

There is no problem changing the y axis major/minor interval.

Code: Select all

oCharts = ThisComponent.getSheets().getByIndex(0).getCharts()
oEmbeddedObject = oCharts.getByIndex(0).getEmbeddedObject()
oDiagram = oEmbeddedObject.getDiagram()
oYAxis = oDiagram.getYAxis()
oYAxis.StepMain = 40.0
oYAxis.StepHelpCount = 3
This doesn't work for x axis!

Trying to use the "TimeInterval" structure say's the property is read-only in the last line below.

Code: Select all

sTimeIntervalMajor = CreateUnoStruct("com.sun.star.chart.TimeInterval")
sTimeIntervalMajor.Number = 4
sTimeIntervalMajor.TimeUnit = 0
sTimeIntervalMinor = CreateUnoStruct("com.sun.star.chart.TimeInterval")
sTimeIntervalMinor.Number = 1
sTimeIntervalMinor.TimeUnit = 0
sTimeIncrement = CreateUnoStruct("com.sun.star.chart.TimeIncrement")
sTimeIncrement.MajorTimeInterval = sTimeIntervalMajor
sTimeIncrement.MinorTimeInterval = sTimeIntervalMinor
sTimeIncrement.TimeResolution = 1

oXAxis = oDiagram.getXAxis()
oXAxis.ExplicitTimeIncrement.MajorTimeInterval = sTimeIntervalMajor
oXAxis.setPropertyValue("ExplicitTimeIncrement", sTimeIncrement)
oXAxis.ExplicitTimeIncrement = sTimeIncrement
Can anyone show a solution how these values can be manipulated? Or confirm that it is not possible?

Thx a lot!

I posted this question first on stackoverflow https://stackoverflow.com/questions/74639398 and have to thank Jim K for helping me with this a lot.
LibreOffice 6.4 on Ubuntu 20.04
JeJe
Volunteer
Posts: 2787
Joined: Wed Mar 09, 2016 2:40 pm

Re: How to set up x axis major/minor values?

Post by JeJe »

If you posted a document with a chart and your code it would help people help without having to first make one themselves.

I don't know about charts but often read only properties are ones that have been set at an object's creation and can only be set then.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
FJCC
Moderator
Posts: 9284
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: How to set up x axis major/minor values?

Post by FJCC »

Does a Line chart have major and minor intervals? The x axis is not numeric and the tick labels are categories. I think you need an xy scatter plot to have major and minor intervals.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
onemorequestion
Posts: 3
Joined: Sat Dec 03, 2022 10:56 pm

Re: How to set up x axis major/minor values?

Post by onemorequestion »

Yes, it does. See the picture below. File attached. Thx.
lo_calc_xaxis_major_tics.png
lo_calc_xaxis_major_tics.png (75.97 KiB) Viewed 985 times
lo_calc_xaxis_major_tics.ods
(21.64 KiB) Downloaded 59 times
LibreOffice 6.4 on Ubuntu 20.04
onemorequestion
Posts: 3
Joined: Sat Dec 03, 2022 10:56 pm

Re: How to set up x axis major/minor values?

Post by onemorequestion »

The macro code:

Code: Select all

REM  *****  BASIC  *****

Sub Chart( oEvent as variant )

Dim oSheet As Variant
Dim oCell As Variant
Dim oCharts As Variant
Dim oChart As Variant
Dim oEmbeddedObject As Variant
Dim oDiagram As Variant
Dim oXAxis As Variant
Dim oYAxis As Variant

oSheet = ThisComponent.CurrentController.getActiveSheet()
oCell  = ThisComponent.CurrentSelection
oCharts = oSheet.getCharts()
oChart = oCharts.getByIndex(0)
oEmbeddedObject = oChart.getEmbeddedObject()
oDiagram = oEmbeddedObject.getDiagram()

rem set major/minor interval for y axis
oYAxis = oDiagram.getYAxis()
oYAxis.StepMain = 10.0
oYAxis.StepHelpCount = 2

rem set major/minor interval for x axis ???
rem above code doesn't work, hence the structur try
sTimeIntervalMajor = CreateUnoStruct("com.sun.star.chart.TimeInterval")
sTimeIntervalMajor.Number = 3
sTimeIntervalMajor.TimeUnit = 0
sTimeIntervalMinor = CreateUnoStruct("com.sun.star.chart.TimeInterval")
sTimeIntervalMinor.Number = 3
sTimeIntervalMinor.TimeUnit = 0
sTimeIncrement = CreateUnoStruct("com.sun.star.chart.TimeIncrement")
sTimeIncrement.MajorTimeInterval = sTimeIntervalMajor
sTimeIncrement.MinorTimeInterval = sTimeIntervalMinor
sTimeIncrement.TimeResolution = 1

oXAxis = oDiagram.getXAxis()
oXAxis.ExplicitTimeIncrement.MajorTimeInterval = sTimeIntervalMajor
oXAxis.setPropertyValue("ExplicitTimeIncrement", sTimeIncrement)
oXAxis.ExplicitTimeIncrement = sTimeIncrement
  
End Sub
LibreOffice 6.4 on Ubuntu 20.04
User avatar
Zizi64
Volunteer
Posts: 11365
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: How to set up x axis major/minor values?

Post by Zizi64 »

Please install and use one of the excellent Object inspection tools: XrayTool or MRI.

Then you will able to list and examine the existing properties and methods of the programming objects of the API.


API: Application Programming Interface.
https://berma.pagesperso-orange.fr/index2.html
https://extensions.libreoffice.org/en/e ... ction-tool
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
karolus
Volunteer
Posts: 1160
Joined: Sat Jul 02, 2011 9:47 am

Re: How to set up x axis major/minor values?

Post by karolus »

Hallo
The MRI-version on LO-extensions is outdated, better use this github with mri1.3.4.oxt
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 7.6 flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
User avatar
Lupp
Volunteer
Posts: 3553
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: How to set up x axis major/minor values?

Post by Lupp »

(Spoken aside one very general remark:)

Completely abandon line graphs that are not x-y graphs.

Students are trained - and need to be trained - that the slope of a line in a graph contains relevant information. This is essential (imo) as a basis for teaching the foundations of calculus.

Line diagrams that are not x-y diagrams violate the principles for which x-y diagrams are useful: in science and engineering, but also in many only superficially related fields.


[Checked with www.DeepL.com/Translator (free version)]
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
Post Reply