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
 how to move legend
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Eagleba91

14 Posts

Posted - 07/16/2012 :  2:21:03 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Does anyone know how to go above moving the legend? It is slightly covering the top of my y-axis on the right side with plenty of room to move it up a little. I have looked for hours both in the user's guide book and online to no avail.

Penn

China
644 Posts

Posted - 07/16/2012 :  10:56:32 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Actually, legend is a GraphObject, with the default name of "Legend". You can check the name by right-clicking on the legend, and then select Programming Control from the context menu. Then you will see the object name in the dialog. So, to change the legend position, you can refer to the example of modifying graph object position. For more details, please refer to here.

Penn
Go to Top of Page

Eagleba91

14 Posts

Posted - 07/18/2012 :  09:39:48 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I have what I believe is the proper code to adjust the position of my legend. For some reason, it only works if I click on the legend to make it the active object though. If I take this code and put it at the end some code to generate a plot it gives me a command error saying, "Origin C Function Runtime Error, Calling members of unattached wrapper class."

// function for moving legend
GraphLayer gl = Project.ActiveLayer();
GraphObject go = gl.GraphObjects("Legend");

Tree tr;
tr.Root.Dimension.Left.dVal = gl.X.To - 23; //To=right, From=left
tr.Root.Dimension.Top.dVal = gl.Y.To+23; //to=top, from = bottom

if( 0 == go.UpdateThemeIDs(tr.Root))
{bool bRet = go.ApplyFormat(tr,true,true);
}
Go to Top of Page

Penn

China
644 Posts

Posted - 07/18/2012 :  10:09:03 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

I guess your graph contains more than one layer and the legend is not in the active layer when the error happens (I can reproduce it in such situation). You mentioned that it worked if you clicked on the legend, actually, this behavior had activated the layer with the legend. You can add the condition as following to test whether the object is valid.

if(!go)
{
    out_str("found no object.");
    return;
}

So, please first make sure the legend is in the graph layer gl in your code.

Penn
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