Can I use a Slider to change axis range in a Calc Chart

You can see some lines in my macro code with rem-ed command 'xray…

The XrayTool is an extension for in-situ examining the programming objects.

Download and install one of the excellent object inspection tools: MRI or XrayTool - if you want to work with the macros efficiently.

"I guess you are saying I should remove my charts and rebuild them by using macros "

Not. You can control any charts by the StarBasic+API macros even if they was created manually.

Always use the native ODF file types - if you want use the macros of the LibreOffice.

Please upload your ODF type sample file here.

Don’t know if you have to had a certain number of posts on here before you can upload a file?

Got the knowledge with upload, had to answer!

You can upload attachmets at your first post (at the “question”). Edit your question, and use the attachment icon.

Yes, realised that Zizi
Apologies, I hacked a lot of the content out so there was not a lot of sense left to the chart but the basics are there.
Will take a while to look at your upload in detail and take a couple of hours off to watch the football
!

Well, that was disappointing. Still, Italy were the better team.

I have added a more complete version of my workbook, hope it makes more sense.

Your sample document was converted from .xls or .xlsm file format, and it is full of unusable styles, macro directories. Please clear up them from the document.

Well yes, Zizi, that was pretty much the object of the exercise! :-:
I have an Excel workbook that I want to move over to Libre and the first thing I noticed that glaringly didn’t work was the macro for the sliders.
Last night wasn’t exactly the “Match of the Century”, which was of course England v Hungary in 1953. I was 6 and remember it well (not)!
Regards and stay safe

Have changed my VBA Project macro code to
Private Sub Sheet6ScrollBar3_Change()
With Sheets(“FIA Championships Charts”).ChartObjects(“Chart 1”).Chart
With .Axes(xlValue, xlPrimary)
automax = False
Min = Sheets(“FIA Championships Charts”).Range(“B19”)
Max = Sheets(“FIA Championships Charts”).Range(“B20”)
End With
End With
End Sub
… now the Slider increments and decrements cell B19, doesn’t error but doesn’t change the chart.
Progress I suppose

Forget your VBA project. Study my sample file and the embedded StarBasic+API macros. See it above, at my answer.

Your sample uses two sliders and the macro directly references each slider setting for its max and min values. Can it instead reference the contents of two cells? I can then use one slider instead of two. Are min and max referenced in a manual/tutorial anywhere?

“Can it instead reference the contents of two cells?”

Yes, you can reference to cells too by your macro. See it in my macro: the labels of the axes are referenced to strings of two NAMED cells. And you can reference to unnamed cells, and their numeric values too.

https://wiki.documentfoundation.org/images/5/5a/CG3412-CalcMacros.pdf

Thanks for the info

Hi Tibor, hope you are well.
Have been overtaken by events, not been 18 months working on this!
I have just re-visited it and have, with the help of another post (61596), Y axis max and min working OK with a couple of Push Buttons . I am trying to tidy it up with a scroll bar which puts the required Max and Min for the axis into cells F12 and F13 but still having a problem getting the contents of the cells into the Axis. The Macro so far…

Sub Scrollbar2click
Dim oSheet As Variant
Dim oCharts As Variant
Dim oChart As Variant
Dim oEmbeddedObject As Variant
Dim oDiagram As Variant
Dim oAxis As Variant
Dim oCellF12 as Variant
oSheet = ThisComponent.getCurrentController().getActiveSheet()
oCharts = oSheet.getCharts()
If oCharts.getCount() < 1 Then Exit Sub
oChart = oCharts.getByIndex(1) ’ Get First Chart or Enumerate all
’ of them with For i = 0 To oCharts.getCount()-1
oEmbeddedObject = oChart.getEmbeddedObject() ’ Get Object in selected frame
oDiagram = oEmbeddedObject.getDiagram() ’ Get diagram from it

Rem Now change values of any property - in this case XAxis and YAxis:
'oAxis = oDiagram.getXAxis()
’ oAxis.AutoMin = False
’ oAxis.AutoMax = False
’ oAxis.Min = oAxis.Min / 2
’ oAxis.Max = oAxis.Max * 1.5
oAxis = oDiagram.getYAxis()
oAxis.AutoMin = False
oAxis.AutoMax = False
oCellF12 = oSheet.GetCellRangeByName(“F12”)
oAxis.Min = oCellF12

End Sub

Which runs to the last line where it errors with “Incorrect Property Value”.
I guess I have not defined oCellF12 correctly, any ideas?
Regards
Uploaded .ods Apologies, it is a bit of a mess.
ScalingAxes3.ods (34.8 KB)

Please upload your actual version of the ODF document here.

A property of an object (oAxis.Min) equals a property on an another object:
oAxis.Min = oCellF12.Value (?)
oAxis.Min = oCellF12.String (?)
oAxis.Min = oCellF12.Formula (?)
oAxis.Min = oCellF12.Formulalocal (?)

1 Like

.value seems to have done the trick!
Have uploaded ScalingAxesFinal document

Thanks for your help
Alan
ScalingAxesFinal.ods (29.5 KB)