Dynamic Y variables in Graph Builder from user selectionHello,
I’m trying to dynamically control multiple Y axes in Graph Builder based on a user Check Box selection.
Hard-coded Y variables work fine, but any dynamic construction fails (Y unresolved, ignored, or empty plot).
I’ve tried:
None work for me.
// Does NOT work
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
// Simulate user selection
Chosen_Ys_list = {"height", "weight"};
// Attempt to build Y list dynamically
Y_List = {};
For( i = 1, i <= N Items( Chosen_Ys_list ), i++,
Insert Into( Y_List, Expr( Y( Eval( Chosen_Ys_list[i] ) ) ) );
);
dt << Graph Builder(
Variables(
X( :age ),
Eval( Y_List ) // <- ignored or errors
)
);
// 2nd try
gb = dt << Graph Builder(
Variables( X( :age ) )
);
gb << Add Variable( Y( :height ) ); // Name Unresolved: Y
Automation and ScriptingData Exploration and VisualizationRe: Dynamic Y variables in Graph Builder from user selectionFor << Add Variable you can find the correct syntax from Scripting Index

Not sure what the final plot is supposed to look like, so here is only one simple example using << Add Variable
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
cols = {"height", "weight"};
gb = dt << Graph Builder(Variables(X(:age)));
For Each({colname}, cols,
Eval(EvalExpr(
gb << Add Variable({Expr(Name Expr(AsColumn(dt, colname))), Role("Y")})
));
);

Re: Dynamic Y variables in Graph Builder from user selectionThere is an issue with your Y_List:

besides that, you will run into issues with the "List".
As an alternative to Add Variable (), you can start with a variable_expr, add more variables, and then use it in the Graph Builder command.
Independent of the approach, the correct positioning of Eval , Eval Expr, Expr, and NameExpr in the code is essential.
the details can be found in the documentation
... and in some community posts
https://www.google.com/search?q=expression+handling++site%3Acommunity.jmp.com
Variables_Expr = Expr(Variables (X(:age)));
For( i = 1, i <= N Items( Chosen_Ys_list ), i++,
Insert Into( Variables_Expr, Eval Expr( Y( Expr(Name Expr(As Column( Chosen_Ys_list[i] ) ) ) );
)));
Eval (Eval Expr(dt << Graph Builder(
Expr(Name Expr(( Variables_Expr ) ))
)));