The Origin Forum
File Exchange
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 I am having trouble centering the y axis label

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Lara Cowan Posted - 08/06/2012 : 3:52:19 PM
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?
5   L A T E S T    R E P L I E S    (Newest First)
Lara Cowan Posted - 08/16/2012 : 3:33:46 PM
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;");
Lara Cowan Posted - 08/09/2012 : 09:18:24 AM
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.
Penn Posted - 08/09/2012 : 02:47:00 AM
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
Lara Cowan Posted - 08/08/2012 : 09:59:38 AM
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
Penn Posted - 08/06/2012 : 10:27:59 PM
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

The Origin Forum © 2008 Originlab Corporation Go To Top Of Page
Snitz Forums 2000