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
 multi-layer graphing

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
jlkautz Posted - 07/05/2007 : 12:55:09 PM
Origin Version (Select Help-->About Origin): 7.5 SR6
Operating System:XP
Hello all,
I'm looking for some help on making a multi-layered graph with origin C. I'm able to make the datasets, create the graph and layers that I need, but when I append the second layer the axis are far off centre. I have two datasets to be plotted against the same X values and I would like to have the Y-axis for the D group to be on the right hand side. Also I'd like to add some different colours. Any help you may have for this would be appreciated.
The code I have so far is this:
if (wp = Project.WorksheetPages(windowName))
if (wks = (Worksheet) wp.Layers(0))
{
GraphPage gp;
if( gp.Create("Origin") )
{
GraphLayer gl = gp.Layers();
Curve curveB(wks,0,1),curveD(wks,0,3);
int bIndex = gl.AddPlot(curveB,IDM_PLOT_SCATTER);
gl.Rescale();
gp.AppendLayers("origin");
gl = gp.Layers(1);
int dIndex = gl.AddPlot(curveD,IDM_PLOT_SCATTER);
gl.Rescale();
}
}

thanks,
Justin
11   L A T E S T    R E P L I E S    (Newest First)
jlkautz Posted - 07/11/2007 : 11:27:46 AM
Hi,

I found the error. Just a simple one. When labelling the right Y axis, I specified it like a left Y axis. The function works well now and the graph looks great. Thanks for all the help.

Justin
jlkautz Posted - 07/11/2007 : 11:03:08 AM
Well, the feeling of completion was short lived, I tried out the code and got this error message in the script box:
"YR.FSIZE is an illegal name for defining a variable. It must not start with a number, nor an operator and may not contain a dot.


YR.ROTATE is an illegal name for defining a variable. It must not start with a number, nor an operator and may not contain a dot."

I used this code, which is--as far as I can see--identical to the code you've helped me out by giving me:
GraphPage gp;
if( gp.Create("Origin") )
{
GraphLayer gl = gp.Layers();

// To pick the plotted columns alter the '1' and '3' for curveB and curveD respectively.
// Remember the computer starts counting at 0. Ie: Column 0 is column A.
Curve curveFirst(wks,0,1),curveSecond(wks,0,3);

int firstIndex = gl.AddPlot(curveFirst,IDM_PLOT_SCATTER); //Adding curveFirst
DataPlot first = gl.DataPlots(0);
first.Curve.Symbol.Size.nVal=9; // Altering size, shape and color.
first.Curve.Symbol.Shape.nVal=2;
first.Curve.Symbol.EdgeColor.nVal = 1;
first.Curve.Symbol.FillColor.nVal = 1;
// To label X-axis, input title in the underscore on the next line and remove comment bars
// LT_execute("label -xb _______"); //x-axis label
LT_execute("label -yl B column"); //y-axis label
gl.LT_execute("ii=yl.fsize"); // save font size
gl.Rescale(); // fits the plot to the graph

// To remove the second dataset from the plot comment out the rest of this block.
gp.LT_execute("layer -n Y"); //creates linked layer w/ right Y axis
gl.Attach(gp.GetName(),1);

int dIndex = gl.AddPlot(curveSecond,IDM_PLOT_SCATTER); // Adding curveSecond
DataPlot second = gl.DataPlots(0);
second.Curve.Symbol.Size.nVal=9;
second.Curve.Symbol.Shape.nVal=2;
second.Curve.Symbol.EdgeColor.nVal = 3;
second.Curve.Symbol.FillColor.nVal = 3;
LT_execute("label -yl D column"); //y-axis label
gl.LT_execute("yr.fsize=ii"); // set font size
gl.LT_execute("yr.rotate=90"); // rotate
gl.Rescale();
}
And here's the problem with the labels:


Thx,
Justin
jlkautz Posted - 07/11/2007 : 10:34:52 AM
Many Thanks Mike and Zach. That should be everything I need for this piece of code. I'm sure there will be more questions soon for my next programs.

cheers,
Justin
Mike Buess Posted - 07/09/2007 : 8:49:45 PM
The code below will work. However, layer properties are much more easily handled with templates.

void gtest(string windowName)
{
WorksheetPage wp = Project.WorksheetPages(windowName);
if( wp )
{
Worksheet wks = wp.Layers(0);
if( wks )
{
GraphPage gp;
if( gp.Create("Origin") )
{
GraphLayer gl = gp.Layers();
Curve curveB(wks,0,1),curveD(wks,0,3);
int bIndex = gl.AddPlot(curveB,IDM_PLOT_SCATTER);
DataPlot first = gl.DataPlots(0);
first.Curve.Symbol.Size.nVal=9; // Altering size, shape and color.
first.Curve.Symbol.Shape.nVal=2;
first.Curve.Symbol.EdgeColor.nVal = 1;
first.Curve.Symbol.FillColor.nVal = 1;
gl.LT_execute("label -yl B Column"); // left Y title
gl.LT_execute("ii=yl.fsize"); // save font size
gl.Rescale();
gp.LT_execute("layer -n Y"); //creates linked layer w/ right Y axis
gl.Attach(gp.GetName(),1);
int dIndex = gl.AddPlot(curveD,IDM_PLOT_SCATTER);
DataPlot second = gl.DataPlots(0);
second.Curve.Symbol.Size.nVal=9;
second.Curve.Symbol.Shape.nVal=2;
second.Curve.Symbol.EdgeColor.nVal = 3;
second.Curve.Symbol.FillColor.nVal = 3;
gp.LT_execute("page.active=2");
gl.LT_execute("label -yr D Column"); // right Y title
gl.LT_execute("yr.fsize=ii"); // set font size
gl.LT_execute("yr.rotate=90"); // rotate
gl.Rescale();
}
}
}
}

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 07/09/2007 8:51:31 PM
jlkautz Posted - 07/09/2007 : 5:00:01 PM
Thanks Zach,

That method worked great for the 'B' plot but the 'D' plot or second plot's Y-label ended up horizontal and overtop of the Y-label for the B plot. Here's the code:
if (wp = Project.WorksheetPages(windowName))
if (wks = (Worksheet) wp.Layers(0))
{
GraphPage gp;
if( gp.Create("Origin") )
{
GraphLayer gl = gp.Layers();

// To pick the plotted columns alter the '1' and '3' for curveB and curveD respectively.
// Remember the computer starts counting at 0. Ie: Column 0 is column A.
Curve curveFirst(wks,0,1),curveSecond(wks,0,3);

int firstIndex = gl.AddPlot(curveFirst,IDM_PLOT_SCATTER); //Adding curveFirst
DataPlot first = gl.DataPlots(0);
first.Curve.Symbol.Size.nVal=9; // Altering size, shape and color.
first.Curve.Symbol.Shape.nVal=2;
first.Curve.Symbol.EdgeColor.nVal = 1;
first.Curve.Symbol.FillColor.nVal = 1;
// To label X-axis, input title in the underscore on the next line and remove comment bars
// LT_execute("label -xb _____");
LT_execute("label -yl B column");//y-axis label
gl.Rescale(); // fits the plot to the graph

// To remove the second dataset from the plot comment out the rest of this block.
gp.LT_execute("layer -n Y"); //creates linked layer w/ right Y axis
gl.Attach(gp.GetName(),1);

int dIndex = gl.AddPlot(curveSecond,IDM_PLOT_SCATTER); // Adding curve D
DataPlot second = gl.DataPlots(0);
second.Curve.Symbol.Size.nVal=9;
second.Curve.Symbol.Shape.nVal=2;
second.Curve.Symbol.EdgeColor.nVal = 3;
second.Curve.Symbol.FillColor.nVal = 3;
LT_execute("label -yl D column");//y-axis label
gl.Rescale();

-Justin
zachary_origin Posted - 07/08/2007 : 04:52:27 AM
you may use the following LabTalk script in Origin C:

LT_execute("label -xb xtitle;"); //change X title
LT_execute("label -yl ytitle;"); // Y title
LT_execute("doc -uw;");//refresh




Edited by - zachary_origin on 07/08/2007 04:53:41 AM
jlkautz Posted - 07/06/2007 : 4:59:18 PM
Thanks a bunch Mike,

How does one change the axis titles by using Origin C?

-Justin
you can probably tell I haven't had that much programming experience and even less in Origin

Edited by - jlkautz on 07/06/2007 5:04:19 PM
Mike Buess Posted - 07/06/2007 : 07:57:47 AM
quote:
the legend doesn't include the dataset D
That can be fixed by changing the worksheet template. Go to the Legends tab of Page properties and check the Include Data Plots from All Layers option. Then save the template.
quote:
the color for data set D doesn't want to change from black.
I can't reproduce that. Color of D symbols changes however I want.

...On closer inspection I see that this isn't working after all. Make the following substitutions.

//b.SetColor(2,true);
b.Curve.Symbol.EdgeColor.nVal = 2;
b.Curve.Symbol.FillColor.nVal = 2;

and

//d.SetColor(3,true);
d.Curve.Symbol.EdgeColor.nVal = 3;
d.Curve.Symbol.FillColor.nVal = 3;

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 07/06/2007 11:19:26 AM

Edited by - Mike Buess on 07/06/2007 12:06:48 PM
jlkautz Posted - 07/05/2007 : 4:56:20 PM
Hello again,

Mike, I just noticed 2 things that I'd like to fix that you might be able to help me with. The first being that the legend doesn't include the dataset D and the color for data set D doesn't want to change from black. Here's the code that basically follows yours, but is what I'm running:

if (wp = Project.WorksheetPages(windowName))
if (wks = (Worksheet) wp.Layers(0))
{
GraphPage gp;
if( gp.Create("Origin") )
{
GraphLayer gl = gp.Layers();
Curve curveB(wks,0,1),curveD(wks,0,3);
int bIndex = gl.AddPlot(curveB,IDM_PLOT_SCATTER);
DataPlot b = gl.DataPlots(0);
b.Curve.Symbol.Size.nVal=9;
b.Curve.Symbol.Shape.nVal=2;
b.SetColor(2,true);
gl.Rescale();
gp.LT_execute("layer -n Y"); //creates linked layer w/ right Y axis
gl.Attach(gp.GetName(),1);
int dIndex = gl.AddPlot(curveD,IDM_PLOT_SCATTER);
DataPlot d = gl.DataPlots(0);
d.Curve.Symbol.Size.nVal=11;
d.Curve.Symbol.Shape.nVal=8;
d.SetColor(3,true);
gl.Rescale();
}
}
jlkautz Posted - 07/05/2007 : 4:22:03 PM
Thanks a bunch Mike, I'll give that a try.

-Justin
Mike Buess Posted - 07/05/2007 : 3:13:31 PM
Hi Justin,

While it's possible to change layer 2's properties in Origin C it's much easier to create a linked layer with LabTalk's layer command. The following function creates such a layer and also sets the symbol shape, size and color in both layers.

void test(string windowName)
{
WorksheetPage wp = Project.WorksheetPages(windowName);
if( wp )
{
Worksheet wks = wp.Layers(0);
if( wks )
{
GraphPage gp;
gp.Create("Origin");
if( gp )
{
GraphLayer gl = gp.Layers(0);
Curve curveB(wks,0,1),curveD(wks,0,3);
int bIndex = gl.AddPlot(curveB,IDM_PLOT_SCATTER);
DataPlot dp1 = gl.DataPlots(0);
dp1.Curve.Symbol.Size.nVal = 9; // symbol size
dp1.Curve.Symbol.Shape.nVal = 1; // square
dp1.SetColor(1,true); // red
gl.Rescale();
gp.LT_execute("layer -n Y"); // create linked layer w/right Y axis
gl.Attach(gp.GetName(),1);
int dIndex = gl.AddPlot(curveD,IDM_PLOT_SCATTER);
DataPlot dp2 = gl.DataPlots(0);
dp2.Curve.Symbol.Size.nVal = 12; // symbol size
dp2.Curve.Symbol.Shape.nVal = 2; // circle
dp2.SetColor(2,true); // green
gl.Rescale();
}
}
}
}


Mike Buess
Origin WebRing Member

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