1

Using a libreoffice basic macro for charts, we can control the maximum value of an axis and turn the automatic mode on/off:

oAxis.AutoMax = False 
oAxis.Max     = 12345

But what are the right property names for

Major Interval
Major Auto
Major Time

which you can set manually

available settings

???

Sep Roland
  • 33,889
  • 7
  • 43
  • 76
onemorequestion
  • 1,056
  • 1
  • 10
  • 15
  • 1
    [**StepMain**](http://www.openoffice.org/api/docs/common/ref/com/sun/star/chart/ChartAxis.html#StepMain) and further down the list? – JohnSUN Dec 01 '22 at 09:52
  • Thx! ```StepMain, StepHelp and StepHelpCount``` are known as properties but I cannot set values to them? Currently I'm using LO version 6.4.2.2. Any thoughts? – onemorequestion Dec 01 '22 at 18:07
  • The same is true for the boolean properties ```AutoStepMain and AutoStepHelp```. Not possible to change their values. But the macro is running fine. As said, ```Max and AutoMax``` properties and some others are working. – onemorequestion Dec 01 '22 at 18:30
  • 1
    I haven't looked into your question specifically, but if setting properties has no effect, you may need to replace the entire object that includes those values. That is, instead of `oAxis.StepMain = 1`, do something like this pseudocode: `oAxisNew = CreateUnoObject("com.sun.star.chart.ChartAxis"); oAxisNew.StepMain = 1; oAxisNew.AutoMax = oAxis.AutoMax; oChart.XAxis = oAxisNew`. – Jim K Dec 01 '22 at 18:56
  • Thx! Setting a value ```oAxisNew.StepMain = 1``` leads to the error: Object variable not set. Any ideas? – onemorequestion Dec 01 '22 at 20:15
  • I was wrong with not being able to change the values of the properties. I can change them all. BUT they have no effect what I controlled by open the axis dialog. Even more strange, changing the values in the dialog for ```StepMain, StepHelp``` related properties and show them on macro start shows only the correct boolean values but the Step numbers aren't correct. ??? – onemorequestion Dec 01 '22 at 20:27

1 Answers1

3

First, I created a chart with Insert Chart > Line > Points and Lines. Modifying the Y axis with code was fairly straightforward.

For both axes, I went into formatting and specified Positioning > Interval Marks > Minor > Outer so that the minor ticks are shown.

oCharts = ThisComponent.getSheets().getByIndex(0).getCharts()
oEmbeddedObject = oCharts.getByIndex(0).getEmbeddedObject()
oDiagram = oEmbeddedObject.getDiagram()
oYAxis = oDiagram.getYAxis()
oYAxis.StepMain = 40.0
oYAxis.StepHelpCount = 3

Here is what the Y Axis properties looked like after running the code:

Y axis properties

AutoStepMain (and the corresponding Major interval checkbox) started out as True, but setting the StepMain value via macro changed it to False.

With the X axis, things were more complex. For the scale, there was a choice of Type, and selecting Date seemed to be the only way to control step settings.

After that, instead of StepMain (which didn't seem to be relevant in this case), there is a complex structure called ExplicitTimeIncrement that specifies the type of increment (Days or Months) along with each value. I didn't dig too far into it, but it looks like it has all of the values you were asking about.

EDIT:

I tried the following code, but none of the values were changed, and the last line throws an error stating that the property is read-only (as also shown by MRI). So perhaps the values cannot be modified via the API.

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

It might also be worth posting at ask.libreoffice.org or forum.openoffice.org to see if anyone there can find a way to modify the values, with a link to this question.

Of course, the UNO API isn't the only possibility. You could write a script to unzip the .ods file and modify the XML code with a parsing library such as xml.etree or regular expressions.

Jim K
  • 12,824
  • 2
  • 22
  • 51
  • Thx a lot for your answer. I used exactly the same code as in your answer. Due to my limited understanding with basic coding, can you give me a hint please, what is the normal way to handle a structur (access). Thx. – onemorequestion Dec 03 '22 at 13:59
  • 1
    See edited answer, which shows how to use structures even though it doesn't give a working solution for the X axis. – Jim K Dec 03 '22 at 19:12
  • Thx a lot Jim K for your help! I asked the forum of AOO. https://forum.openoffice.org/en/forum/viewtopic.php?t=109001 – onemorequestion Dec 03 '22 at 21:30
  • 1
    What type of chart are you using? In your question to the AOO Forum you say it is a line chart. These don't have an x-axis, they have a category axis like in a bar chart. Only X-Y (Scatter) charts have an actual x-axis. The procedure given in @JimK's answer for setting the properties of the y-axis works for me when applied to the x-axis of an X-Y (Scatter) chart. – Howard Rudd Dec 05 '22 at 15:32