cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
Neo
Neo
Level VI

How to pass Y variable in Graph Builder from a List in JSL?

The example script below does what I need for a fixed small number of parameters which I want to plot on the Y-axis. 

How to automate this for a list which is supplied to Y from above?

(The X variable/column remains fixed but the number of elements going to Y can change and is supplied from a another script)

Names Default To Here (1);
Clear Log ();
dt = open("$sample_data\Big Class.jmp");
y_values = {"name", "age", "sex", "weight"};
Graph Builder(
    Show Control Panel( 0 ),
    Variables( X( :height), 
    Y( column(dt, y_values[1]) ), 
    Y( column(dt, y_values[2]) ),
    Y( column(dt, y_values[3]) ),
    Y( column(dt, y_values[4]) ) 
    ),
    Elements( Position( 1, 1 ), Points( X, Y, Legend( 1 ) ) ),
	Elements( Position( 1, 2 ), Points( X, Y, Legend( 2 ) ) ),
	Elements( Position( 1, 3 ), Points( X, Y, Legend( 3 ) ) ),
	Elements( Position( 1, 4 ), Points( X, Y, Legend( 4 ) ) )
);

Also, how does one handle the Elements () in this case.

When it's too good to be true, it's neither
2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: How to pass Y variable in Graph Builder from a List in JSL?

This isn't only option of building this but can give some ideas. Also search scripting index for Variable and Element for GraphBuilderbox

Names Default To Here(1);

dt = Open("$sample_data\Big Class.jmp");

y_values = {"name", "age", "sex", "weight"};

variables_expr = Expr(Variables(X(:height)));

For Each({y_col}, y_values,
	temp_expr = Expr(Y());
	Insert Into(temp_expr, Name Expr(AsColumn(dt, y_col)));
	Insert Into(variables_expr, Name Expr(temp_expr));
);


gb_expr = Expr(Graph Builder(
	Show Control Panel(0)
));

Insert Into(gb_expr, Name Expr(variables_expr));

For Each({y_col, idx}, y_values,
	Eval(EvalExpr(
		Insert Into(gb_expr,
			Name Expr(Elements(Position(1, Expr(idx)), Points(X, Y, Legend(Expr(idx)))))
		)
	));
);

Show(Name Expr(gb_expr));
Eval(gb_expr);

 

Edit:

One example using Add Variable()

Names Default To Here(1);

dt = Open("$sample_data\Big Class.jmp");

y_values = {"name", "age", "sex", "weight"};

variables_expr = Expr(Variables(X(:height)));

gb = dt << Graph Builder(
	// Ignore Platform Preferences(1),
	Show control Panel(0),
	Variables(X(:height))
);

gb << inval;

For Each({y_col, idx}, y_values,
	Eval(EvalExpr(
		gb << Add Variable({Expr(Name Expr(As Column(dt, y_col))), Role("Y")})
	));

// if you just want points, you shouldn't need this, but smoother idx is 2 instead of 1
/*	gb << Remove Element(1, idx, 1); 
	Eval(EvalExpr(
		gb << Add Element(1, Expr(idx), {Type("Points"), X, Y, Legend(Expr(idx))})
	));
*/
);

gb << Update window;
gb << Remove Element(1, N Items(y_values), 2);  // 1 or 2 for smoother idx, depending on how GB is built
-Jarmo

View solution in original post

Neo
Neo
Level VI

Re: How to pass Y variable in Graph Builder from a List in JSL?

Current Report()[TextEditBox( 1 )] << set text( "NewTitle" );

This works for me.

When it's too good to be true, it's neither

View solution in original post

10 REPLIES 10
hogi
Level XII

Re: How to pass Y variable in Graph Builder from a List in JSL?

You could generate symbols var and gb for the expressions

Var= Expr(variables(x(:height)))
gb =Expr(Graph Builder())


And then use InsertInto in a For loop to fill var with the Ys , then insert NameExpr(var) into gb and then use another For loop to add the Elements expressions.

Neo
Neo
Level VI

Re: How to pass Y variable in Graph Builder from a List in JSL?

@hogi Thanks, I am afraid I need some more hand holding as I have never used Expr () and Insert NameExpr () functions previously. It would be useful if you could provide an example with the example script I added in my OP.

When it's too good to be true, it's neither
jthi
Super User

Re: How to pass Y variable in Graph Builder from a List in JSL?

This isn't only option of building this but can give some ideas. Also search scripting index for Variable and Element for GraphBuilderbox

Names Default To Here(1);

dt = Open("$sample_data\Big Class.jmp");

y_values = {"name", "age", "sex", "weight"};

variables_expr = Expr(Variables(X(:height)));

For Each({y_col}, y_values,
	temp_expr = Expr(Y());
	Insert Into(temp_expr, Name Expr(AsColumn(dt, y_col)));
	Insert Into(variables_expr, Name Expr(temp_expr));
);


gb_expr = Expr(Graph Builder(
	Show Control Panel(0)
));

Insert Into(gb_expr, Name Expr(variables_expr));

For Each({y_col, idx}, y_values,
	Eval(EvalExpr(
		Insert Into(gb_expr,
			Name Expr(Elements(Position(1, Expr(idx)), Points(X, Y, Legend(Expr(idx)))))
		)
	));
);

Show(Name Expr(gb_expr));
Eval(gb_expr);

 

Edit:

One example using Add Variable()

Names Default To Here(1);

dt = Open("$sample_data\Big Class.jmp");

y_values = {"name", "age", "sex", "weight"};

variables_expr = Expr(Variables(X(:height)));

gb = dt << Graph Builder(
	// Ignore Platform Preferences(1),
	Show control Panel(0),
	Variables(X(:height))
);

gb << inval;

For Each({y_col, idx}, y_values,
	Eval(EvalExpr(
		gb << Add Variable({Expr(Name Expr(As Column(dt, y_col))), Role("Y")})
	));

// if you just want points, you shouldn't need this, but smoother idx is 2 instead of 1
/*	gb << Remove Element(1, idx, 1); 
	Eval(EvalExpr(
		gb << Add Element(1, Expr(idx), {Type("Points"), X, Y, Legend(Expr(idx))})
	));
*/
);

gb << Update window;
gb << Remove Element(1, N Items(y_values), 2);  // 1 or 2 for smoother idx, depending on how GB is built
-Jarmo
Neo
Neo
Level VI

Re: How to pass Y variable in Graph Builder from a List in JSL?

@jthi Thanks. This works for me, but I cannot change the default Chart title. How to do this via JSL?

When it's too good to be true, it's neither
jthi
Super User

Re: How to pass Y variable in Graph Builder from a List in JSL?

Depends on what you define as title.

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
gb = Graph Builder(
	Variables(X(:height), Y(:weight)),
	Elements(Points(X, Y), Smoother(X, Y))
);

gb << Title("Test");

And if you consider it to be the text edit box above graph builder, change it manually and then modify the script created by JMP.

	SendToReport(Dispatch({}, "graph title", TextEditBox, {Set Text("asdsad")}))

and you can get even more information if you have JMP17 and use properties

jthi_0-1696344778375.png

So something like

Report(gb)[TextEditBox(1)] << Set Text("12313213");

might work depending on your report

 

-Jarmo
Neo
Neo
Level VI

Re: How to pass Y variable in Graph Builder from a List in JSL?

@jthi Thanks. For the straightforward case you show, I know how to put the chart title (as you show), but how to do this for the case below?

Names Default To Here(1);

dt = Open("$sample_data\Big Class.jmp");

y_values = {"name", "age", "sex", "weight"};

variables_expr = Expr(Variables(X(:height)));

For Each({y_col}, y_values,
	temp_expr = Expr(Y());
	Insert Into(temp_expr, Name Expr(AsColumn(dt, y_col)));
	Insert Into(variables_expr, Name Expr(temp_expr));
);


gb_expr = Expr(Graph Builder(
	Show Control Panel(0)
));

Insert Into(gb_expr, Name Expr(variables_expr));

For Each({y_col, idx}, y_values,
	Eval(EvalExpr(
		Insert Into(gb_expr,
			Name Expr(Elements(Position(1, Expr(idx)), Points(X, Y, Legend(Expr(idx)))))
		)
	));
);

Show(Name Expr(gb_expr));
Eval(gb_expr);
When it's too good to be true, it's neither
jthi
Super User

Re: How to pass Y variable in Graph Builder from a List in JSL?

Get reference to the graph builder and both of those ideas should work

-Jarmo
Neo
Neo
Level VI

Re: How to pass Y variable in Graph Builder from a List in JSL?

@jthi Thanks but do not see Get Reference () in Scripting Index (I am on JMP 16.2.0). Do you mean get the window name of the graph builder window?

When it's too good to be true, it's neither
Neo
Neo
Level VI

Re: How to pass Y variable in Graph Builder from a List in JSL?

Current Report()[TextEditBox( 1 )] << set text( "NewTitle" );

This works for me.

When it's too good to be true, it's neither