Author |
Topic |
|
Chris2
20 Posts |
Posted - 09/20/2010 : 05:03:20 AM
|
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
|
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 |
|
|
Chris2
20 Posts |
Posted - 09/20/2010 : 06:27:41 AM
|
Thanks a lot! Works great! |
|
|
|
Topic |
|
|
|