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
 merging number of different plots in different lay
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

olsy

29 Posts

Posted - 10/29/2014 :  07:55:28 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): Origin Pro 8.5
Operating System: Win7

Hi!
I can not solve one problem:
I would like to merge different number of plots in one layer.
For example, I have 66 different graphs.
I want to merge 1st, 7th, 13th and so on in one graph.
The same with 2nd, 8th and so on...
3rd, 9th....
...
6th, 12th ...

I create 6 layers. When I try to merge my plots, as the results only 1st and 7th are merged.

/Collects All Worksheets from the current Workbook with names beginning with "PlotParam"

WorksheetPage wpSource=Project.Pages(-1);
if(wpSource.IsValid()==true)
{
WorksheetPage WPtarget;
string strName = "PlotParam";
strName.TrimLeft();
strName.TrimRight();
strName.MakeLower();
if(WPtarget.Create("xxx",CREATE_HIDDEN)==true)
{
Worksheet WksEmpty(WPtarget.Layers(0));
WksEmpty.SetName("xxx"+strName);
int NumLayers=0;
foreach (Layer Layr in wpSource.Layers)
{
Worksheet WksSearch(Layr);
if(WksSearch.IsValid()==true)
{
string strWksName=WksSearch.GetName();
if(is_str_match_begin(strName,strWksName)==true)
{

Worksheet wksdata(Layr);
DataRange dr1;
DataRange dr2;
DataRange dr3;
DataRange dr4;
DataRange dr5;
DataRange dr6;

dr1.Add(wksdata, 1, "X");
dr1.Add(wksdata, 5, "Y");
dr2.Add(wksdata, 1, "X");
dr2.Add(wksdata, 6, "Y");
dr3.Add(wksdata, 1, "X");
dr3.Add(wksdata, 7, "Y");
dr4.Add(wksdata, 1, "X");
dr4.Add(wksdata, 8, "Y");
dr5.Add(wksdata, 1, "X");
dr5.Add(wksdata, 9, "Y");
dr6.Add(wksdata, 1, "X");
dr6.Add(wksdata, 10, "Y");

GraphPage gp1;
gp1.Create("origin", CREATE_HIDDEN);
GraphLayer gl1 = gp1.Layers();

//GAP_GROUP_PLOTS is specified by default, so if data range has multiple plots, they will be grouped
gl1.AddPlot(dr1, IDM_PLOT_LINESYMB);
int nMode = ALM_CUSTOM;
bool bCreate = true; // true, if no legend will create one
bool bReconstruct = false; // true, if always delete the original legend and create a new one; false, not delete old one just update
string strCustomMode = "@LN"; // use Column Units label as legend
legend_update(gl1,nMode, bCreate, bReconstruct, strCustomMode); // to update the legend loaded in from template
gl1.Rescale();
gp1.SetShow();


GraphPage gp2;
gp2.Create("origin", CREATE_HIDDEN);
GraphLayer gl2 = gp2.Layers();

//GAP_GROUP_PLOTS is specified by default, so if data range has multiple plots, they will be grouped
gl2.AddPlot(dr2, IDM_PLOT_LINESYMB);

gl2.Rescale();
legend_update(gl2,nMode, bCreate, bReconstruct, strCustomMode); // to update the legend loaded in from template
gp2.SetShow();

GraphPage gp3;
gp3.Create("origin", CREATE_HIDDEN);
GraphLayer gl3 = gp3.Layers();

//GAP_GROUP_PLOTS is specified by default, so if data range has multiple plots, they will be grouped
gl3.AddPlot(dr3, IDM_PLOT_LINESYMB);

gl3.Rescale();
legend_update(gl3,nMode, bCreate, bReconstruct, strCustomMode); // to update the legend loaded in from template
gp3.SetShow();

GraphPage gp4;
gp4.Create("origin", CREATE_HIDDEN);
GraphLayer gl4 = gp4.Layers();

//GAP_GROUP_PLOTS is specified by default, so if data range has multiple plots, they will be grouped
gl4.AddPlot(dr4, IDM_PLOT_LINESYMB);

gl4.Rescale();
legend_update(gl4,nMode, bCreate, bReconstruct, strCustomMode); // to update the legend loaded in from template
gp4.SetShow();

GraphPage gp5;
gp5.Create("origin", CREATE_HIDDEN);
GraphLayer gl5 = gp5.Layers();

//GAP_GROUP_PLOTS is specified by default, so if data range has multiple plots, they will be grouped
gl5.AddPlot(dr5, IDM_PLOT_LINESYMB);

gl5.Rescale();
legend_update(gl5,nMode, bCreate, bReconstruct, strCustomMode); // to update the legend loaded in from template
gp5.SetShow();

GraphPage gp6;
gp6.Create("origin", CREATE_HIDDEN);
GraphLayer gl6 = gp6.Layers();

//GAP_GROUP_PLOTS is specified by default, so if data range has multiple plots, they will be grouped
gl6.AddPlot(dr6, IDM_PLOT_LINESYMB);

gl6.Rescale();
legend_update(gl6,nMode, bCreate, bReconstruct, strCustomMode); // to update the legend loaded in from template
gp6.SetShow();

NumLayers++;
}
}
}

ErrorExit: WPtarget.Destroy();
}
}

int iGraphCount=Project.GraphPages.Count(); //Current number of graphs in project
printf("grapnumber = %d\n", iGraphCount);

for (int i=1; i<=iGraphCount; i++)
{
int k=i+6;

GraphPage gp1("Graph"+i); // graph1
GraphPage gp7("Graph"+k); // graph2

GraphLayer gl1 = gp1.Layers(0); // first layer in graph1
GraphLayer gl7 = gp7.Layers(0); // first layer in graph2

DataPlot dp1 = gl1.DataPlots(0); // first data plot in graph1
DataPlot dp7 = gl7.DataPlots(0); // first data plot in graph2

XYRange xy1, xy7;
dp1.GetDataRange(xy1); // get XY data range
dp7.GetDataRange(xy7);

GraphPage gp;
gp.Create("Origin", CREATE_HIDDEN); // create a new graph
GraphLayer gl = gp.Layers();
gl.AddPlot(xy1, IDM_PLOT_LINESYMB); // add data plot to the layer
gl.AddPlot(xy7, IDM_PLOT_LINESYMB);

gl.Rescale();

gp1.Destroy(); // destroy graph1
gp7.Destroy(); // destroy graph2

gl.GroupPlots(0);
gl.LT_execute("legend");

}

Can someone probably find my mistake?

thanks!

jasonzhao

China
262 Posts

Posted - 10/30/2014 :  02:39:40 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello,

X-function merge_graph is provided for user to merge graph with easy interface and avoid complexity, this page introduce the usage and I/O for merge_graph:
http://www.originlab.com/doc/X-Function/ref/merge_graph.
Based on the process you described, the merge function can be written like this :

merge_graph option:=specified graphs:="Graph1"+char(10)$+"Graph7"+char(10)$+"Graph13" row:=3 col:=1;
and "for()" statement could be used for loop through all graphs.
would you like to think about this strategy?

Best regards,
Jason Zhao
OriginLab Tech Service

Edited by - jasonzhao on 10/30/2014 02:41:25 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