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 add plot to linked x-axis plot
 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/10/2012 :  3:34:17 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
I am able to create a plot and add a linked layer so they share an x axis. I am having trouble adding my second plot to this layer. What I want is to have two separate line graphs that share an x-axis on the same plot. any help you can provide would be greatly appreciated.

void plotA()
{
Worksheet wks = Project.ActiveLayer();
if( !wks )
{
out_str("Please activate one worksheet with data");
return;
}

DataRange dr;
dr.Add(wks,6, "X"); //7th column for current
dr.Add(wks,7,"Y"); //8th column for voltage



//creat graph window
GraphPage gp;
gp.Create("Origin");
GraphLayer gl = gp.Layers();


//Plot XY data range as line
int nPlotIndex = gl.AddPlot(dr, IDM_PLOT_LINE);

//returns plot index (offset is 0), else return -1 for error
if(nPlotIndex >= 0)
{gl.Rescale(); //rescale axes to show all data points

}

/* Function for adding layer with linked x-axis */

GraphLayer gm = Project.ActiveLayer(); //calling active layer
GraphPage gq = gm.GetPage();

bool bBottom = false, bLeft = false, bTop = false, bRight = true;
int nLinkTo = gm.GetIndex(); //New added layer link to the active layer
bool bActivateNewLayer = true;



int nLayerIndex = page_add_layer(gq,bBottom,bLeft,bTop,bRight,
ADD_LAYER_INIT_SIZE_POS_SAME_AS_PREVIOUS, bActivateNewLayer,nLinkTo);

GraphLayer go = Project.ActiveLayer();

GraphObject grYR = go.GraphObjects("YR"); //get right y-axis

grYR.Text = "Optical Power (W)";

go.GetPage().Refresh();


}

Penn

China
644 Posts

Posted - 07/10/2012 :  9:40:43 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

I am afraid that you have used the code of adding plot to layer in your code.

quote:

DataRange dr;
dr.Add(wks,6, "X"); //7th column for current
dr.Add(wks,7,"Y"); //8th column for voltage



//creat graph window
GraphPage gp;
gp.Create("Origin");
GraphLayer gl = gp.Layers();


//Plot XY data range as line
int nPlotIndex = gl.AddPlot(dr, IDM_PLOT_LINE);


So, you can add the code like below to add another plot to the newly added linked layer.

DataRange dr1;
dr1.Add(wks,8, "X"); //9th column for current
dr1.Add(wks,9,"Y"); //10th column for voltage

//Plot XY data range as line
int nPlotIndex1 = go.AddPlot(dr1, IDM_PLOT_LINE);


Penn
Go to Top of Page

Eagleba91

14 Posts

Posted - 07/11/2012 :  2:29:40 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I am successfully able to plot my second graph by using the code:

DataRange dr1;
dr1.Add("X","[Book1]Sheet1!G:G"); //Column G is current
dr1.Add("Y","[Book1]Sheet1!H:H"); //Column H is voltage

//Plot XY data range as line
int nPlotIndex1 = go.AddPlot(dr1, IDM_PLOT_LINE);

The only problem is when I import new data it will be generate to a workbook called "Book2" which means that my second plot isn't getting updated. it is continuously spitting out the same plot using the data from Book1. I am trying to figure out a way to implement a loop where it checks if there is a workbook with a higher number (i.e. Book1 vs Book2) so that I can have my plots update automatically when I use a new Workbook. Any help is much appreciated.
Go to Top of Page

Eagleba91

14 Posts

Posted - 07/11/2012 :  3:40:10 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
even worse is I found out instead of progressing from Book1 to Book2 successively with each import, they are all named Book1 with a short name derived from the file I am importing from. an Example is CLF26 - Book1 vs CLF48 - Book1. Files are imported in no particular order so that makes a loop useless. I need to figure out a way to differentiate between all the books open so I only use the most recently opened one to generate my plots.
Go to Top of Page

Penn

China
644 Posts

Posted - 07/11/2012 :  11:46:00 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

First of all, I need to figure out how you import the data, by Origin C code, or by menu.

If by Origin C code, you'd better first create a workbook first, and then import the data into it. And then make the plot by using this workbook (worksheet), but not by using the hard code like "[Book1]Sheet1!G:G".

If by menu of File: Import: Single ASCII..., you can specify the import mode to import the data to replace the existing data, and not change the name of the worksheet and workbook. See the image of the settings.


Penn
Go to Top of Page

Eagleba91

14 Posts

Posted - 07/12/2012 :  09:50:46 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I figured out how to partially solve the problem. Before I import each time I am deleting the workbook and graph page that already exists. Problem is I need to save the graphs each time they are generated. I tried exporting them as a JPEG file to my drive, but I keep getting the error "function or variable export_page_to_image not found" I am running 8.6 so I don't understand why it isn't recognizing the global function. This is the last step for a process I am working on. As always, help is much appreciated.

void delete_wksPg()
{ WorksheetPage wksPg;
wksPg = Project.WorksheetPages.Item(0); //Get first workbook in project
if (wksPg) //if there is a workbook
wksPg.Destroy(); //delete the workbook

GraphPage gp;
gp = Project.GraphPages.Item(0); //Get first graph in project
if (gp) //if there is a graph
gp.Destroy(); //delete the graph
}

//Function to export graph
GraphPage gp;
gp = Project.ActiveLayer().GetPage();
if(gp) //if active page is a graph
{
string strFileName;
strFileName.Format("U:\test\myname\%s.emf", gp.GetName());
export_page_to_image(strFileName, "JPG",gp,800,600);
}
Go to Top of Page

Penn

China
644 Posts

Posted - 07/12/2012 :  9:02:29 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Please check the prototype of export_page_to_image here. The one you tried to use has the first six parameters no default values. However, you just pass five arguments, that is why the compiler says this function "not found". Please refer to the second example in that page.

Penn

Edited by - Penn on 07/12/2012 9:02:53 PM
Go to Top of Page

Eagleba91

14 Posts

Posted - 07/19/2012 :  2:33:04 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
back to plotting: I will be importing a bunch of files that have various sheet names. In order to graph the data as it is imported I am trying to get the name of each sheet and graph using the sheet name. I use the GetName() function to store the name as a string, but for some reason I can't input the string in the DataRange function as so -

Worksheet wks = Project.ActiveLayer();
string strn=wks.GetName();
printf("name of sheet is %s\n",strn);

if( !wks )
{
out_str("Please activate one worksheet with data");
return;
}
DataRange dr;
dr.Add("X","[Book1]%s!G:G",strn);
dr.Add("Y","[Book1]%s!H:H",strn);

//create graph window
GraphPage gp;
gp.Create("Origin");
GraphLayer gl = gp.Layers();

//Plot XY data range as line
int nPlotIndex = gl.AddPlot(dr, IDM_PLOT_LINE);

//returns plot index (offset is 0), else return -1 for error
if(nPlotIndex >= 0)
{
gl.Rescale(); //rescale axes to show all data points
}
Go to Top of Page

Penn

China
644 Posts

Posted - 07/19/2012 :  9:29:35 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Please refer to the Add method page. I am afraid the way you used this method is not correct. So, you'd better check the prototypes in document (by menu Help: Programming: Origin C) before you use it.

In you case, if you really want to use the worksheet name, you need to construct the string to specify the right column. For example:

string strX = "[" + wks.GetPage().GetName() + " ]" + wks.GetName() + "!G:G";
string strY = "[" + wks.GetPage().GetName() + " ]" + wks.GetName() + "!H:H";
DataRange dr;
dr.Add("X", strX);
dr.Add("Y", strY);

Actually, you don't need to get the name by using the second or third prototypes.

Penn

Edited by - Penn on 07/19/2012 9:43:11 PM
Go to Top of Page

Eagleba91

14 Posts

Posted - 07/24/2012 :  4:19:51 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Yes! that top part is exactly what I was looking to do. Didn't realize I had to call everything like that. Right now I am trying to do some column data manipulation using formulas. For some reason when I try to multiply a column by a double or int there is no output. Here is what I am trying to work with:

Worksheet wks = Project.ActiveLayer();
wks.AddCol(); //Add one more column

Column colG;
colG.Attach(wks,6);

Column colH;
colH.Attach(wks,7);

double d0 = 2;
Column colU;
colU.Attach(wks,20);
colU.SetFormula("col(G)-(col(H)*%d)",d0);
colU.ExecuteFormula();

Thanks for all of your help up to this point Penn. Not sure how I would get through these problems without you.
Go to Top of Page

Penn

China
644 Posts

Posted - 07/24/2012 :  9:08:49 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Again, please check the prototype of SetFormula here, for example:

string strFormula;
strFormula.Format("col(G)-(col(H)*%f)", d0);  // d0 is double type, need %f, but not %d
colU.SetFormula(strFormula);


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