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

ovince

Yugoslavia
Posts

Posted - 10/09/2006 :  12:14:08 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi All,

Is there any good example how to insert one graph into another? Forum Search does not provide it.

thanks
Oliver

zachary_origin

China
Posts

Posted - 10/10/2006 :  12:22:47 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Did you mean adding a inset to a graph. If it is, here just give a brief example:



void Add_Inset_Graph()
{
//Graph1 is the source graph
//maybe there are more than one layer in the graph.
//if it is, you need a loop to get all the layers

GraphLayer glSource("Graph1", 0);
//Graph2 is the destination graph
GraphPage gpDest("Graph2");

//add a new layer to hold the source graph
gpDest.AppendLayers("origin");
GraphLayer glDestNew = gpDest.Layers(gpDest.Layers.Count()-1);

//get the data plots from the source graph,
for(int nPlot=0; nPlot<glSource.DataPlots.Count(); nPlot++)
{
DataPlot dpSource = glSource.DataPlots(nPlot);

//In ver7.5, GraphLayer::AddPlot() only supports Curve as parameter, so need get the Curve from DataPlot
Curve crv(dpSource);
int nRes = glDestNew.AddPlot(crv);
}

//Using LabTalk script to control the positon of the layer
LT_execute("layer 20 20 40 5;");
}



Zachary
OriginLab Technical Services.


Edited by - zachary_origin on 10/10/2006 12:26:58 AM
Go to Top of Page

ovince

Yugoslavia
Posts

Posted - 10/10/2006 :  02:16:50 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
hi Zachary,

Thanks for code.


I dont know where it goes wrong but I have something like this:

Before using 'void Add_Inset_Graph()'




After using 'void Add_Inset_Graph()'





Graph2 has only 1 layer. What might be the reason for this failor?

Thanks
oliver
Go to Top of Page

zachary_origin

China
Posts

Posted - 10/10/2006 :  03:43:23 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Oliver,

I got the problem. It is because before running the function, the source graph (Graph1) is active, then the LabTalk scipt in the function takes efforts in the source graph rather than the destination graph (Graph2). If you active the destination graph, it will work. Therefore, we need add a line
set_active_layer(glDestNew); 
right before the last line of in the function. Try it.


Zachary
OriginLab Technical Services.

Edited by - zachary_origin on 10/10/2006 03:52:00 AM
Go to Top of Page

ovince

Yugoslavia
Posts

Posted - 10/10/2006 :  04:04:34 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
hi

Yes it works but I obtain this



1.
That is, the x range of the histogram is changed (0-0.5 initially to 0-10 in the inset graph ). Consequently, the histogram in the inset graph is shrinked (I hope only shrinked; I can't zoom it enough to be able to see what happend )

2.
The legend of the histogram also changed his form and content.

Any idea why?

oliver
Go to Top of Page

zachary_origin

China
Posts

Posted - 10/11/2006 :  11:43:14 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Oliver,

Ok, I realized the problem. The reason for the result you got is that when using the line gpDest.AppendLayers("origin"); to add a new layer, a template "origin" is used. So in the new layer, the graph is plotted in the style of that template, e.g. the column bar is changed to line, x scale is changed to 0-10. To set it be as same as the source graph, we need use gpDest.AppendLayers("Column"); to add layer, and after the graph is copied, the scale of the axis should also be adjusted in accord with the original one. These will be alot troublesome. So I think it would be better plot the graph directly the destination layer rather than first plot it in another graph page and then copy it to the destination graph.


Zachary
OriginLab Technical Services.


Edited by - zachary_origin on 10/11/2006 11:51:02 AM
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