cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
Choose Language Hide Translation Bar
View Original Published Thread

Handling Conditional Display of Y-Axis Variables in JSL for Graph Building

BabyDoragon
Level II

When using `graph built`, how can I describe the requirement in JSL that certain Y-axis variables, which may not always appear, should be displayed if they have values and not displayed if they have no values? The following two methods have not been effective.

 

1.

dt = Open("$SAMPLE_DATA/Big Class.jmp");
Graph Builder(
	Size( 534, 450 ),
	Show Control Panel( 0 ),
	Variables( X( :sex ), try(Y( :bbb )), Y( :height ), Y( :weight ) ),
	Elements( Position( 1, 1 ), Points( X, Y, Legend( 13 ) ) ),
	Elements( Position( 1, 2 ), Points( X, Y, Legend( 14 ) ) ),
	Elements( Position( 1, 3 ), Points( X, Y, Legend( 15 ) ) )
);

2.

dt = Open("$SAMPLE_DATA/Big Class.jmp");
Graph Builder(
	Size( 534, 450 ),
	Show Control Panel( 0 ),
	Variables( X( :sex ), Y( :bbb ), Y( :height ), Y( :weight ) ),
	Elements( Position( 1, 1 ), Points( X, Y, Legend( 13 ) ) ),
	Elements( Position( 1, 2 ), Points( X, Y, Legend( 14 ) ) ),
	Elements( Position( 1, 3 ), Points( X, Y, Legend( 15 ) ) )
);
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Handling Conditional Display of Y-Axis Variables in JSL for Graph Building

You can build the expression or add variable later

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
gb = dt << Graph Builder(
	Size(534, 450),
	Show Control Panel(0),
	Variables(X(:sex), Y(:height), Y(:weight)),
	Elements(Position(1, 1), Points(X, Y, Legend(13))),
	Elements(Position(1, 2), Points(X, Y, Legend(14)))
);
dt << new column("A", Numeric, Continuous, Formula(Row()));

extra_cols = {"height", "A"};

For Each({extra_col}, extra_cols,
	Eval(EvalExpr(
		gb << Add Variable({Expr(NameExpr(AsColumn(dt, extra_col))), Role("Y")});
	));
);

Depending on what you are trying to do, there can be quite a few things to take into account (order, type of plots, legend, ...)

 

If I remember correctly this might have something related to this topic Scripters Club Recording: JSL in Graph Builder 

-Jarmo

View solution in original post

3 REPLIES 3


Re: Handling Conditional Display of Y-Axis Variables in JSL for Graph Building

Hi @BabyDoragon, is bbb a column that either exists or not and this is what we need to check, or bbb is always there but some values(rows) are missing ?

BabyDoragon
Level II


Re: Handling Conditional Display of Y-Axis Variables in JSL for Graph Building

The default value of bbb is {}, and sometimes it may be stored as a variable, for example in the following two cases.

1.

dt = Open("$SAMPLE_DATA/Big Class.jmp");
bbb={};
bbb="age";
Graph Builder(
	Size( 534, 450 ),
	Show Control Panel( 0 ),
	Variables( X( :sex ), Y( as column(bbb)), Y( :height ), Y( :weight ) ),
	Elements( Position( 1, 1 ), Points( X, Y, Legend( 13 ) ) ),
	Elements( Position( 1, 2 ), Points( X, Y, Legend( 14 ) ) ),
	Elements( Position( 1, 3 ), Points( X, Y, Legend( 15 ) ) )
);

2.

dt = Open("$SAMPLE_DATA/Big Class.jmp");
bbb={};
//bbb="age";
Graph Builder(
	Size( 534, 450 ),
	Show Control Panel( 0 ),
	Variables( X( :sex ), Y( as column(bbb)), Y( :height ), Y( :weight ) ),
	Elements( Position( 1, 1 ), Points( X, Y, Legend( 13 ) ) ),
	Elements( Position( 1, 2 ), Points( X, Y, Legend( 14 ) ) ),
	Elements( Position( 1, 3 ), Points( X, Y, Legend( 15 ) ) )
);

I hope to enable the graph to automatically include or exclude this item based on whether there are any variables currently in bbb.

jthi
Super User

Re: Handling Conditional Display of Y-Axis Variables in JSL for Graph Building

You can build the expression or add variable later

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
gb = dt << Graph Builder(
	Size(534, 450),
	Show Control Panel(0),
	Variables(X(:sex), Y(:height), Y(:weight)),
	Elements(Position(1, 1), Points(X, Y, Legend(13))),
	Elements(Position(1, 2), Points(X, Y, Legend(14)))
);
dt << new column("A", Numeric, Continuous, Formula(Row()));

extra_cols = {"height", "A"};

For Each({extra_col}, extra_cols,
	Eval(EvalExpr(
		gb << Add Variable({Expr(NameExpr(AsColumn(dt, extra_col))), Role("Y")});
	));
);

Depending on what you are trying to do, there can be quite a few things to take into account (order, type of plots, legend, ...)

 

If I remember correctly this might have something related to this topic Scripters Club Recording: JSL in Graph Builder 

-Jarmo