[Solved] Secondary axis using java

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
jfuster
Posts: 3
Joined: Wed Jul 28, 2021 10:06 pm

[Solved] Secondary axis using java

Post by jfuster »

Hello,

I´m trying to add a secondary axis in a plot with two numeric series. Im trying to do something like this but it does not work:

Code: Select all

 com.sun.star.chart.XTwoAxisYSupplier secondAxis = multiServiceFactory.createInstance(com.sun.star.chart.XTwoAxisYSupplier.class, "com.sun.star.chart.ChartTwoAxisYSupplier");
 XPropertySet secondAxisProps = secondAxis.getSecondaryYAxis();
    
 if (secondAxisProps!=null) {
    	try {
    		secondAxisProps.setPropertyValue("HasSecondaryYAxis", new Boolean(true));
    		secondAxisProps.setPropertyValue("HasSecondaryYAxisDescription", new Boolean(true));
    	} catch (Exception e) {
    		e.printStackTrace();
        }  
}
I'm getting a nullPointer. What is the right way to do it? Could you please help?

Thanks in advance.
Last edited by jfuster on Sun Aug 01, 2021 6:55 pm, edited 3 times in total.
OpenOffice 7.1.5.2 on Windows 10.0
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Secondary axis using java

Post by Zizi64 »

Are you using an object inspection tool (XrayTool, MRI) for the programming?
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.
jfuster
Posts: 3
Joined: Wed Jul 28, 2021 10:06 pm

Re: Secondary axis using java

Post by jfuster »

Thank you Zizi64. I´m calling LO from an external java program: it first load a Calc sheet with data, reads data from two rows, inserts a Chart and saves the Chart in png format. I´m trying to add a secondary Axis to this Chart.
I do not know if XrayTool can work outside a Macro, can it? I found another object inspector "Development Tool" developed by Tomaž Vajngerl but I cannot enable the option menu to run it.
OpenOffice 7.1.5.2 on Windows 10.0
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Secondary axis using java

Post by Zizi64 »

I do not know if XrayTool can work outside a Macro or not, but you can list and examine the properties and methods of the programming objects with the Xray inside a LO macro. And them (maybe) you can use the informations outside the macros.

I assume that the functions of the LO API are largely the same when called inside or outside macros.

API: Application Programming Interface.
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
Villeroy
Volunteer
Posts: 31270
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Secondary axis using java

Post by Villeroy »

You can instanciate service ""mytools.Mri" and then call method inspect(obj)
In Basic:

Code: Select all

  oMRI = CreateUnoService( "mytools.Mri" )
  oMRI.inspect( MriTargetObject )
This should work with any language with MRI extension installed.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
jfuster
Posts: 3
Joined: Wed Jul 28, 2021 10:06 pm

[Solved] Secondary axis using java

Post by jfuster »

Thank you Villeroy and Zizi64. MRI has been very helpful to figure out the right interface and property to be set:

Code: Select all

com.sun.star.chart.XTwoAxisYSupplier secondAxis =  UnoRuntime.queryInterface(com.sun.star.chart.XTwoAxisYSupplier.class, xDiagram);
XPropertySet secondAxisProps = secondAxis.getSecondaryYAxis();
secondAxisProps.setPropertyValue("Visible", new Boolean(true));
OpenOffice 7.1.5.2 on Windows 10.0
Post Reply