cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
rleeper
Level III

How do I use a variable inside the graph builder script with a loop?

Hi all.  I am using a variable CD to keep track of several different products.  I would like to use a for loop to run the graph builder and under the Variables function of the graph substitute my variable for the Y axis name.

 

I have this under graph builder script:

 

 

 

Graph Builder(

 

Variables( X( :DateTime ), Y( :BLU14031717111005_100_200 ) ),

 

Elements( Points( X, Y, Legend( 11 ), Jitter( 1 ), Error Bars( "Range" ) ) ),

 

{},

 

"BLU14031717111005_100_200",

 

ScaleBox,

 

{Add Ref Line( 2120, Solid, "Medium Light Red", "LCL", 2 ),

 

Add Ref Line( 2340, Solid, "Medium Light Red", "HCL", 2 )}

 

),

 

Dispatch( {}, "400", LegendBox, {Position( {0} )} )

 

 

I want to change the :blu14031717........ to a variable that will change depending on the for loop iteration.  I would also like the graph title to change with each iteration.  Any help would be most appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
David_Burnham
Super User (Alumni)

Re: How do I use a variable inside the graph builder script?

Here is an example - it uses the Eval function to evaluate the variable that contains the column reference:

 

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
For( i = 1, i <= N Cols( dt ), i++,
	yCol = Column( dt, i );
	strTitle = "Graph #" || Char( i );
	Graph Builder(
		Show Control Panel( 0 ),
		Variables( X( :weight ), Y( Eval( i ) ) ),
		Elements( Points( X, Y, Legend( 1 ) ) ),
		SendToReport( Dispatch( {}, "graph title", TextEditBox, {Set Text( strTitle )} ) )
	);
);

Unfortunately I still have no idea how to cut and paste JSL whilst maintaining its formatting - this is what it looks like:

6819_jsl.JPG

David Burnham

-Dave

View solution in original post

6 REPLIES 6
David_Burnham
Super User (Alumni)

Re: How do I use a variable inside the graph builder script?

Here is an example - it uses the Eval function to evaluate the variable that contains the column reference:

 

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
For( i = 1, i <= N Cols( dt ), i++,
	yCol = Column( dt, i );
	strTitle = "Graph #" || Char( i );
	Graph Builder(
		Show Control Panel( 0 ),
		Variables( X( :weight ), Y( Eval( i ) ) ),
		Elements( Points( X, Y, Legend( 1 ) ) ),
		SendToReport( Dispatch( {}, "graph title", TextEditBox, {Set Text( strTitle )} ) )
	);
);

Unfortunately I still have no idea how to cut and paste JSL whilst maintaining its formatting - this is what it looks like:

6819_jsl.JPG

David Burnham

-Dave
rleeper
Level III

Re: How do I use a variable inside the graph builder script?

David,

 

Thank you!

 

I just changed one line and now the name of the graph is the column name, you rock!

 

strTitle = Char( yCol )
pmroz
Super User

Re: How do I use a variable inside the graph builder script?

Dave - if you copy/paste the code from JMP to MS-Word, and then re-copy/paste from MS-Word to this forum, it will retain the formatting.  Clunky but it works.

David_Burnham
Super User (Alumni)

Re: How do I use a variable inside the graph builder script?

Thanks Peter

-Dave
ankursaxena
Level I

Re: How do I use a variable inside the graph builder script?

@Hi,

I have a quick question on this. (If someone sees this message, this comes roughly two years after the last reply).

The above code works perfectly fine for me, but I am not understanding why Eval(i) is used for Y variable in the Graph builder code in the line below. Shouldn't it be Eval(yCol(i)) ? Eval(i) will just give 1,2,3 ... etc ,then how does it work fine?

           Variables( X( :weight ), Y( Eval(i) ) ),

Thanks,

-Ankur

David_Burnham
Super User (Alumni)

Re: How do I use a variable inside the graph builder script?

You are correct - I think it was a typo - it should be Eval( yCol )

-Dave