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

Chris2

20 Posts

Posted - 09/20/2010 :  05:03:20 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Windows Vista
Origin 8.1

Hello,

is it possible to call special columns with their longnames?

in Laptalk I use the following code to plot this way:

plotxy iy:= [cool.dat]cool!((Time,lambda),(Time,lambda2)) ogl:=[Graph1]1! plot:=200;

in Origin C I tried this one (First example of code in Origin C):


DataRange dr;
dr.Add(wksDest2, Time, "X");
dr.Add(wksDest2, lambda, "Y");
dr.Add(wksDest2, lambda2, "Y");
GraphPage gp ("Graph1");
GraphLayer gl = gp.Layers(0);
gl.AddPlot(dr, IDM_PLOT_LINE);
legend_update(gl);
gp.SetShow();

Unfortunately it didn't work, so I tried another one (Second example of Code in Origin C):

for( int ii = 0; ii < wksDest2.GetNumCols() ; ii++ )
{
string strName;
wksDest2.Columns(ii).GetLongName();
strName = wksDest2.Columns(ii).GetLongName();

DataRange dr;
if(strName == "Time")
{
dr.Add(wksDest2, ii, "X");
}
if(strName == "lambda")
{
dr.Add(wksDest2, ii, "Y");
}
if(strName == "lambda2")
{
dr.Add(wksDest2, ii, "Y");
}
GraphPage gp ("Graph1");
GraphLayer gl = gp.Layers(0);
gl.AddPlot(dr, IDM_PLOT_LINE);
legend_update(gl);
gp.SetShow();
}

Now it works but Origin puts the legend to the center of the graph and doesn't give the second Y-Column a separate color. When I run the first example of code in Origin C with the number of the columns instead of their longnames it works properly (however this isn't possible in my case, I absolutely need the longnames).

Hope you can help me!


Penn

China
644 Posts

Posted - 09/20/2010 :  06:16:15 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

For the first example code:
There is no such prototype for DataRange::Add method like the way you used. You can take a look the existing three prototypes.

For the second example code:
You can try the following code first.

void test_DataRange()
{
	Worksheet wksDest2 = Project.ActiveLayer();
	DataRange dr;  // declare outside the for loop
	
	for( int ii = 0; ii < wksDest2.GetNumCols() ; ii++ )
	{
		string strName;
		wksDest2.Columns(ii).GetLongName();
		strName = wksDest2.Columns(ii).GetLongName();

		if(strName == "Time")
		{
			dr.Add(wksDest2, ii, "X");
		}
		if(strName == "lambda")
		{
			dr.Add(wksDest2, ii, "Y");
		}
		if(strName == "lambda2")
		{
			dr.Add(wksDest2, ii, "Y");
		}
	}
	
	// plot outside the for loop
	GraphPage gp ("Graph1");
	GraphLayer gl = gp.Layers(0);
	gl.AddPlot(dr, IDM_PLOT_LINE);
	legend_update(gl);
	gp.SetShow();
}

You can see that, I declare the DataRange and make the plot outside the for loop. The difference is that, the above code will make two plots as a grouped plot and will use the color increment, just as you highlight both columns and then make a graph, however, the code you used will make two plots in the graph layer separately, just as you highlight one column and plot it first, then add another plot to the graph layer.

Penn
Go to Top of Page

Chris2

20 Posts

Posted - 09/20/2010 :  06:27:41 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks a lot! Works great!
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