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
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Creating Multiple Graphs from Multiple Worksheets

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 HyperlinkUpload FileInsert 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
Vainsworth93 Posted - 09/09/2014 : 11:46:47 AM
Origin Ver. and Service Release (Select Help-->About Origin): 9.1
Operating System: XP

Hi! I'm an undergrad working on a research project that is to create some code to automate the processing of large amounts of data. I've been able to figure out the multiple import, so there's no problem there, but I can't seem to figure out how to get the information I import to graph, or to have it create a multiple graphs.
Obviously I'm not looking for someone to hand me the answer, but suggestions/advice/a bit of help would be greatly appreciated!
12   L A T E S T    R E P L I E S    (Newest First)
Sophy Posted - 10/23/2014 : 03:50:31 AM
quote:
Originally posted by Vainsworth93

Hey again!
I'm Curious, if I were to want Origin to select files to graph based on their file name, (say, there are two files that both contain '0T' in their file name), so that there would be two layers per graph, where in this code would I edit that in?
Also in what format would I put that? Would I have something similar to gp.getname( "the beginning of the filename \\0T") ?



Hi, I'm not sure what you want(select files to graph base on their file name? what is the file? does it have anything to do with the graph you are creating?). If you want to plot data on a graph of two layers, better create your own template, then when you create a graph with your template, it will already have two layers on it(or you can create with gp.Create("Origin.otp"), and then use gp.AddLayer() to add another layer on it.
Vainsworth93 Posted - 09/30/2014 : 12:26:08 PM
Hey again!
I'm Curious, if I were to want Origin to select files to graph based on their file name, (say, there are two files that both contain '0T' in their file name), so that there would be two layers per graph, where in this code would I edit that in?
Also in what format would I put that? Would I have something similar to gp.getname( "the beginning of the filename \\0T") ?
Vainsworth93 Posted - 09/16/2014 : 09:39:21 AM
Thank you very much, this worked!
greg Posted - 09/12/2014 : 09:25:58 AM
As I said .. the SECOND version. Your version of the function with no arguments won't work since
Worksheet wks = Project.WorksheetPages(-1).Layers(-1)
is meaningless.

///// SECOND version /////
void Graph(Folder& fdr, GraphLayer& gl, bool bRecursive = false)
{
if ( !fdr || !gl )
return;

//loop all pages and plot data on worksheets
foreach(PageBase pg in fdr.Pages)
{
if ( pg.GetType() == EXIST_WKS ) //check whether is WorksheetPage
{
WorksheetPage wksPage(pg);
foreach(Layer wkslyr in wksPage.Layers)
{
Worksheet wks(wkslyr);
gl.AddPlot(wks); //plot all curves from wks to gl, as line
}
}
}
}
///// END SECOND version /////

Here is how your first version could be re-written to handle looping over all worksheets in the the project:
void Graph()
{
// Construct the Curve object specifying the x and y datasets to
// be used for the dataplot
foreach(PageBase pg in Project.Pages)
{
if ( pg.GetType() == EXIST_WKS ) //check whether is WorksheetPage
{
WorksheetPage wksPage(pg);
foreach(Layer wkslyr in wksPage.Layers)
{
Worksheet wks(wkslyr);
Curve cc(wks, 0, 1);
// the graph layer needs to be initialized:
GraphPage gp;
gp.Create("Origin");
GraphLayer lay = gp.Layers(0);
if(lay)
{
// Add the dataplot to the graph:
int nIndex = lay.AddPlot(cc, IDM_PLOT_LINE);
lay.Rescale();
// Display the index of the data plot just added:
out_int("Dataplot index = ", nIndex);
}
}
}
}
}

This version creates multiple graphs with one plot rather than one graph with multiple plots. Re-write if you want something else.
Vainsworth93 Posted - 09/11/2014 : 12:16:44 PM
I don't understand how you were able to remove the Worksheet wks = Project.WorksheetPages(-1).Layers(-1) line because when I remove it from my code, my output box tells me that the variable 'wks' is no longer defined....
greg Posted - 09/11/2014 : 11:56:22 AM
I tested your code [ the second version without the non-sensical Worksheet wks = Project.WorksheetPages(-1).Layers(-1) ] with the IDM_PLOT_LINE removed and it worked in every release of Origin 9.1.

Using foreach with the Pages collection is the correct approach.
Vainsworth93 Posted - 09/11/2014 : 10:36:45 AM
Okay, so that didn't work, it didn't really change what the program was doing at all, really. Is there a way I could enter a range of (0,-1) [meaning the first to the last worksheet] to be graphed? I've tried to put in that range for this line
Worksheet wks = Project.WorksheetPages(-1).Layers(-1);

but it tells me that "Member function Project::WorksheetPages not defined or does not have matching prototype."
Vainsworth93 Posted - 09/10/2014 : 10:21:04 AM
Alright! I'll try that, thank you for your help!
greg Posted - 09/10/2014 : 09:33:45 AM
Try removing IDM_PLOT_LINE leaving just

gl.AddPlot(wks); // Use default of IDM_PLOT_UNKNOWN

It's possible there is no matching Line plot style holder in your template in which case the plot will not be added. The AddPlot method returns a -1 ( indicating a problem ) in such cases.
Vainsworth93 Posted - 09/09/2014 : 2:59:41 PM
At the moment I'm using a code I found in one of the examples within the Origin website. It will only allow me to graph either the very first worksheet or the very last, I've been trying to get it to graph all work sheets into the separate graphs.


void Graph()
{
// Construct the Curve object specifying the x and y datasets to be used for
// the dataplot
Worksheet wks = Project.WorksheetPages(-1).Layers(-1);
if(wks)
{
Curve cc(wks, 0, 1);

// the graph layer needs to be initialized:
GraphPage gp;
gp.Create("Origin");
GraphLayer lay = gp.Layers(0);
if(lay)
{
// Add the dataplot to the graph:
int nIndex = lay.AddPlot(cc, IDM_PLOT_LINE);
lay.Rescale();
// Display the index of the data plot just added:
out_int("Dataplot index = ", nIndex);
}
}
}

void Graph(Folder& fdr, GraphLayer& gl, bool bRecursive = false)
{
if ( !fdr || !gl )
return;

//loop all pages and plot data on worksheets
foreach(PageBase pg in fdr.Pages)
{
if ( pg.GetType() == EXIST_WKS ) //check whether is WorksheetPage
{
WorksheetPage wksPage(pg);
foreach(Layer wkslyr in wksPage.Layers)
{
Worksheet wks(wkslyr);
gl.AddPlot(wks, IDM_PLOT_LINE); //plot all curves from wks to gl, as line
}
}
}
}
Vainsworth93 Posted - 09/09/2014 : 2:45:40 PM
Thank You! However, it says that the example you linked is for "multiple layers", will specifying a template allow for multiple single-layered graphs?
greg Posted - 09/09/2014 : 2:18:38 PM
Here's a start:
http://ocwiki.originlab.com/index.php?title=Category:Graphing

Where that example says:
gp.Create("Origin");

you can specify any of our built-in graph templates or one of your own custom templates.

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