cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
JmpAround182
Level I

How to Dynamically Add Element Statements for a Graph using JSL

Hey guys I'm pretty new to JMP and JSL, but am pretty familiar with coding.  I'm trying to create a JSL script that will take a list of parameters names (that I define in the "PlotVars" array) and then plot them all in separate plots on the same graph.  I want this script to work regardless of how many parameters are defined in this array (in case I want to add or subtract parameters for each use).  I can get my script to produce this (using the code below), but all of the plots default to using points, and I would like them to use a line instead.  My understanding of how to do this is to use multiple element statements for each position.  I believe the problem lies with my second line where I initialize the "var_line" variable.  If I initialize it as Expr() then it will produce the element statements but won't run them properly.  Same thing if I initialize them as Parse().  Open to any ideas to solve this though.  I'm using JMP 18.

 

Edit (jthi): Added jsl formatting

var_expr = Expr(
	Variables(X(As Column("Start Alignment of " || DataSet_1)))
);
var_line = Expr();//Unable to dymanically add elements to the graph.  still unsure why
 
For(i = 1, i <= N Items(PlotVars), i++,
	Insert Into(var_expr, Eval Expr(Y(As Column(PlotVars[Expr(i)] || " of " || DataSet_1), )));
	Insert Into(
		var_expr,
		Eval Expr(Y(As Column(PlotVars[Expr(i)] || " of " || DataSet_2), Position(Expr(i)), ))
	);
	Insert Into(
		var_line,
		Eval Expr(Elements(Position(1, Expr(i)), Line(X, Y(1), Y(2)), Legend(4)))
	);
);
 
plot = Substitute(
		Expr(
			Data Table("Comparison of" || DataSet_1 || "with" || DataSet_2) <<
			Graph Builder(Size(809, 629), Show Control Panel(0), vvv, yyy)
		),
	Expr(vvv), Name Expr(var_expr),
	Expr(yyy), Name Expr(test)
);
 
Eval(plot);

 

<

var_expr = Expr(Variables(X( as column("Start Alignment of " || DataSet_1) )));
var_line = Expr();//Unable to dymanically add elements to the graph.  still unsure why
 
for(i=1, i<=N Items(PlotVars),i++,
Insert Into(var_expr, Eval Expr(Y( as column(PlotVars[expr(i)] || " of " || DataSet_1),)));
Insert Into(var_expr, Eval Expr(Y( as column(PlotVars[expr(i)] || " of " || DataSet_2), Position(expr(i)),))); 
Insert Into(var_line, Eval Expr(Elements(Position(1,expr(i)),Line(X,Y(1),Y(2)),Legend(4))));
);
 
plot = Substitute(
Expr(
Data Table( "Comparison of" || DataSet_1 || "with" ||DataSet_2 ) <<
Graph Builder(
Size( 809, 629 ),
Show Control Panel( 0 ),
vvv,
yyy
)),
Expr(vvv), Name Expr(var_expr),
Expr(yyy), Name Expr(test)
);
 
Eval(plot);

>

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How to Dynamically Add Element Statements for a Graph using JSL

View more...
Names Default To Here(1); 

dt = Open("$SAMPLE_DATA/Semiconductor Capability.jmp");
plotvars = {"NPN1", "NPN2", "NPN3", "NPN4", "PNP1"};
xcol = "wafer";

gb_expr = Expr(Graph Builder(Size(809, 629), Show Control Panel(0)));
var_expr = EvalExpr(Variables(X(Expr(NameExpr(As Column(dt, xcol))))));
For Each({colname, idx}, plotvars,
	Insert Into(var_expr, Eval Expr(Y(Expr(NameExpr(As Column(dt, colname))))));
);
Insert Into(gb_expr, Name Expr(var_expr));

For(idx = 1, idx <= N Items(plotvars), idx++,
	elem_expr = Substitute(
		Expr(Elements(Position(1, _pos_), Line(X, Y, Legend(_lgnd_)))),
		Expr(_pos_), idx, 
		Expr(_lgnd_), idx
	);
	Insert Into(gb_expr, Name Expr(elem_expr));
);
// Show(gb_expr);

gb = Eval(EvalExpr((Send(dt, Expr(gb_expr)))));
gb_expr = Graph Builder(
	Size(809, 629),
	Show Control Panel(0),
	Variables(X(:wafer), Y(:NPN1), Y(:NPN2), Y(:NPN3), Y(:NPN4), Y(:PNP1)),
	Elements(Position(1, 1), Line(X, Y, Legend(1))),
	Elements(Position(1, 2), Line(X, Y, Legend(2))),
	Elements(Position(1, 3), Line(X, Y, Legend(3))),
	Elements(Position(1, 4), Line(X, Y, Legend(4))),
	Elements(Position(1, 5), Line(X, Y, Legend(5)))
);
-Jarmo

View solution in original post

4 REPLIES 4
jthi
Super User

Re: How to Dynamically Add Element Statements for a Graph using JSL

What do you wish your graph to look like? How does the script look like when JMP creates it? How does it compare to your script which you create with JSL?

Data Table("Comparison of" || DataSet_1 || "with" || DataSet_2) <<
Graph Builder(
	Size(809, 629),
	Show Control Panel(0),
	Variables(
		X(As Column("Start Alignment of " || DataSet_1)),
		Y(As Column(PlotVars[1] || " of " || DataSet_1)),
		Y(As Column(PlotVars[1] || " of " || DataSet_2), Position(1)),
		Y(As Column(PlotVars[2] || " of " || DataSet_1)),
		Y(As Column(PlotVars[2] || " of " || DataSet_2), Position(2))
	),
	test
)

There is also quite a lot of material related to this, dynamically building graph builder. Here are few Scripters Club Recording: JSL in Graph Builder , Reply All: How to script dynamic content for Graph Builder 

-Jarmo
JmpAround182
Level I

Re: How to Dynamically Add Element Statements for a Graph using JSL

The script creates the graph's exactly as I want them, except it creates them using points/smoother in the element statements (note that variables are removed to shorten the script length).  This is the graph code from the script output:

Graph Builder(
	Size( 809, 629 ),
	Show Control Panel( 0 ),
	Variables(
		...
		)
	),
	Elements(
		Position( 1, 1 ),
		Points( X, Y( 1 ), Y( 2 ), Legend( 1 ) ),
		Smoother( X, Y( 1 ), Y( 2 ), Legend( 2 ) )
	),
	Elements(
		Position( 1, 2 ),
		Points( X, Y( 1 ), Y( 2 ), Legend( 3 ) ),
		Smoother( X, Y( 1 ), Y( 2 ), Legend( 4 ) )
	),
	Elements(
		Position( 1, 3 ),
		Points( X, Y( 1 ), Y( 2 ), Legend( 5 ) ),
		Smoother( X, Y( 1 ), Y( 2 ), Legend( 6 ) )
	),
	Elements(
		Position( 1, 4 ),
		Points( X, Y( 1 ), Y( 2 ), Legend( 7 ) ),
		Smoother( X, Y( 1 ), Y( 2 ), Legend( 8 ) )
	),
	Elements(
		Position( 1, 5 ),
		Points( X, Y( 1 ), Y( 2 ), Legend( 9 ) ),
		Smoother( X, Y( 1 ), Y( 2 ), Legend( 10 ) )
	)
);

And I would prefer it to use Lines instead:

Graph Builder(
	Size( 696, 590 ),
	Show Control Panel( 0 ),
	Variables(
		...
		)
	),
	Elements( Position( 1, 1 ), Line( X, Y( 1 ), Y( 2 ), Legend( 11 ) ) ),
	Elements( Position( 1, 2 ), Line( X, Y( 1 ), Y( 2 ), Legend( 12 ) ) ),
	Elements( Position( 1, 3 ), Line( X, Y( 1 ), Y( 2 ), Legend( 13 ) ) ),
	Elements( Position( 1, 4 ), Line( X, Y( 1 ), Y( 2 ), Legend( 14 ) ) ),
	Elements( Position( 1, 5 ), Line( X, Y( 1 ), Y( 2 ), Legend( 15 ) ) )
);

Whenever try to "Insert Into" the elements statement it just adds a nested elements statement instead of separate elements statements.  And the graph builder seems to just ignore those nested elements statements.

jthi
Super User

Re: How to Dynamically Add Element Statements for a Graph using JSL

View more...
Names Default To Here(1); 

dt = Open("$SAMPLE_DATA/Semiconductor Capability.jmp");
plotvars = {"NPN1", "NPN2", "NPN3", "NPN4", "PNP1"};
xcol = "wafer";

gb_expr = Expr(Graph Builder(Size(809, 629), Show Control Panel(0)));
var_expr = EvalExpr(Variables(X(Expr(NameExpr(As Column(dt, xcol))))));
For Each({colname, idx}, plotvars,
	Insert Into(var_expr, Eval Expr(Y(Expr(NameExpr(As Column(dt, colname))))));
);
Insert Into(gb_expr, Name Expr(var_expr));

For(idx = 1, idx <= N Items(plotvars), idx++,
	elem_expr = Substitute(
		Expr(Elements(Position(1, _pos_), Line(X, Y, Legend(_lgnd_)))),
		Expr(_pos_), idx, 
		Expr(_lgnd_), idx
	);
	Insert Into(gb_expr, Name Expr(elem_expr));
);
// Show(gb_expr);

gb = Eval(EvalExpr((Send(dt, Expr(gb_expr)))));
gb_expr = Graph Builder(
	Size(809, 629),
	Show Control Panel(0),
	Variables(X(:wafer), Y(:NPN1), Y(:NPN2), Y(:NPN3), Y(:NPN4), Y(:PNP1)),
	Elements(Position(1, 1), Line(X, Y, Legend(1))),
	Elements(Position(1, 2), Line(X, Y, Legend(2))),
	Elements(Position(1, 3), Line(X, Y, Legend(3))),
	Elements(Position(1, 4), Line(X, Y, Legend(4))),
	Elements(Position(1, 5), Line(X, Y, Legend(5)))
);
-Jarmo
JmpAround182
Level I

Re: How to Dynamically Add Element Statements for a Graph using JSL

Awesome this idea worked.  I needed to just insert the Elements command at the graph builder level, not try to build the elements commands into an expression on its own.

Recommended Articles