The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 I am having trouble centering the y axis label
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Lara Cowan

USA
9 Posts

Posted - 08/06/2012 :  3:52:19 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version: Origin 8.5.1 SR2 b315
Operating System: Windows 7 Enterprise SP1

I am having trouble centering the y axis label.
In my code I loop over each layer and set the axis scales and text.

1) I tried to center the y axis using the following:
LT_execute("yl.y = layer.y.from + (layer.y.to - layer.y.from) / 2;");

It did not work when I executed the code.
However, if I set a break point and run through it, then it centers correctly.


2) I have also tried centering the label using this code:
GraphObject grYL = layer.GraphObjects("YL");
grYL.Y = layer.Y.From + ( (layer.Y.To - layer.Y.From) / 2.0 );

It acts the same way as my first method.


3) Next I tried setting the y position outside of the loop using this code:
LT_execute("int lLayerCount = 0; doc -e LW { if( lLayerCount != 18 ){ yl.y = layer.y.from + ( (layer.y.to - layer.y.from) / 2 ); } lLayerCount++; }");

It too did not work unless a break point was set.


4) The only way I have gotten the labels to center correctly is to set the script in the template's Programming Control to the following:
yl.y = layer.y.from + ( layer.y.to - layer.y.from ) / 2;
yl.x = layer.x.from - ( layer.x.to - layer.x.from )*0.7 - yl.dx;

But if I use this method then the users won't be able to move the labels on their own or will have to delete the labels' script. (I had to set the x position because otherwise the labels were positioned at the left side of the page.)

What am I doing wrong?

Penn

China
644 Posts

Posted - 08/06/2012 :  10:27:59 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

I think what you do is the right way. However, I have tried in both Origin 8.5.1 and 8.6, but cannot see the problem you mentioned. Is the axis title already at the center of the axis? If so, you cannot see the change. You can try to move the label to other position to see whether it can work.

By the way, you can download the demo version of Origin 8.6 here to have a try to see whether the same problem is still there. If yes, you can send your opj to tech support for more help.

Penn
Go to Top of Page

Lara Cowan

USA
9 Posts

Posted - 08/08/2012 :  09:59:38 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The y label is not already centered. It is off by quite a bit.
In the image you can see that layer 1 (bottom) is off a bit and layer 2 (top graph) is off more.


I changed my prior code to check the output
bOK=LT_execute("double lNewYCenter = layer.y.from + (layer.y.to - layer.y.from) / 2; lNewYCenter=;");
bOK=LT_execute("yl.y = lNewYCenter; yl.y=;");

The output window displayed the following:
lNewYCenter=5
yl.y=6.0406091370558
lNewYCenter=5
yl.y=7.6649746192893

Why isn't yl.y being set?


For some reason, if I set yl.y twice it will work
bOK=LT_execute("double lNewYCenter = layer.y.from + (layer.y.to - layer.y.from) / 2; lNewYCenter=;");
bOK=LT_execute("yl.y = lNewYCenter; yl.y=; yl.y = lNewYCenter; yl.y=; ");

This outputs:
lNewYCenter=5
yl.y=6.0406091370558
yl.y=4.9915397631134
lNewYCenter=5
yl.y=7.6649746192893
yl.y=4.9915397631134

Edited by - Lara Cowan on 08/08/2012 10:07:05 AM
Go to Top of Page

Penn

China
644 Posts

Posted - 08/09/2012 :  02:47:00 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

I cannot still reproduce your issue. Have you tried to run the LabTalk script in Script Window, but not by Origin C? If still not work, please send your project, together with your code to tech support. Please refer to this post in your email.

Penn
Go to Top of Page

Lara Cowan

USA
9 Posts

Posted - 08/09/2012 :  09:18:24 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The script works when I run it in the script window.
Something in my code must be resetting the yl.y value.

The code was originally written for Origin 7.
I cannot send in the project or code.
Thank you for trying to help.
Go to Top of Page

Lara Cowan

USA
9 Posts

Posted - 08/16/2012 :  3:33:46 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
OK, I have found the solution. I needed to refresh the window before setting the YL position.

Layer position and axis position were set just before this code
LT_execute("doc -UWF;"); // <- SOLUTION IS TO ADD THIS LINE                           
bOK = LT_execute("layer.y.showLabels = 1;");
string strLabels = wksSetup.TCell(lSetupRowIndex,yLabelIdx);
bOK = LT_execute("label -sa -yl "+strLabels+";"); 
bOK=LT_execute("yl.y = ( y1 + y2 )/2;");
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000