如何根据条件使用 JSL 在 Graph Builder 中动态分配 X 或 Y 变量?
大家好,JMP 社区,
I'm trying to build a dynamic Graph Builder report in JSL where the list of X variables is determined by certain conditions (e.g., flags like includeSite, includeWW, etc.). The goal is to flexibly add or remove columns from the X-axis based on runtime logic.
我尝试了几种方法,包括使用:
X( :ColumnName )
X( Column("ColumnName") )
Expr( X(...) )
Substitute(...) and Eval(...)
然而,我经常遇到如下错误:
Name Unresolved: X in access or evaluation of 'X'
Bad Argument( Column(...) )
我正在寻找一种可靠且正确的方法来:
这是我的目标的简化版本:
xVars = {};
If( includeSite, Insert Into( xVars, :Site ) );
If( includeWW, Insert Into( xVars, :WW ) );
// add remaining fixed columns...
Graph Builder(
Variables(
// <- How can I inject xVars here properly?
Y( :Measurement )
),
Elements(
Points( Y( :Measurement ) )
)
);
I want to avoid generating multiple separate graph blocks depending on each condition. Is there a supported or recommended way to dynamically build up the X() list for Graph Builder?
提前致谢!
自动化和脚本基础数据分析与建模质量与工艺工程回复:如何根据条件使用 JSL 在 Graph Builder 中动态分配 X 或 Y 变量?您可以先尝试使用<<添加变量
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
gb = Graph Builder(Variables(X(:age), Y(:weight)), Elements(Points(X, Y), Smoother(X, Y)));
Wait(0.5);
gb << Add Variable({:height, Role("Y")});
如果这不起作用,你可能必须构建 X 作为表达式,然后将其评估为图形生成器
回复:如何根据条件使用 JSL 在 Graph Builder 中动态分配 X 或 Y 变量?使用内置函数(如@jthi建议的)是处理此类主题的好方法。
如果您想遵循通过定义和组合 JSL 代码块(“表达式”) 来动态编写 JSL 代码的原始想法,请查看@Jasean的博客文章☝。
和
Expr( X(...) )
你很接近了, 代替和评估是框架的其他部分。
也许是最重要的函数: 名称表达式() 。它可以用于访问存储在变量 (=name) 中的表达式,而无需对其进行求值,例如通过
y= Expr(X( "ColumnName") );
Name Expr(y);
you will get X( "ColumnName") 而不是

有关表达式处理的其他资源:
JMP 中的表达式处理:技巧和陷阱门 - JMP 用户社区
脚本编写者俱乐部,第 9 节:高级 JSL
表达式处理函数:第一部分 - 解开 Expr()、NameExpr()、Eval() 等难题
回复:如何根据条件使用 JSL 在 Graph Builder 中动态分配 X 或 Y 变量?因此,借助表达式() 、 求值() 、 代替()和名称表达式() ,
Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
xVars = Expr(X);
Insert Into( xVars, Expr(:age) );
Eval(Substitute(Expr(Graph Builder(
Variables(
__xVars__,
Y( :height )
)
)
), Expr(__xVars__) , Name Expr(xVars)));
回复:如何根据条件使用 JSL 在 Graph Builder 中动态分配 X 或 Y 变量?我更喜欢使用Eval Expr( ) 而不是 Substitute( ) - 它的工作原理如下
“在评估整个内容之前,先搜索表达式()并评估其内容”:
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
xVars = Expr( X );
Insert Into( xVars, Expr( :age ) );
Eval(
Eval Expr(
Graph Builder(
Variables( Expr( Name Expr( xVars ) ), Y( :height ) )
)
)
);
因此,JMP 必须找到:

并对其进行求值。请注意名称 Expr() 。如上一篇文章所述,这确保 JMP 仅查找xVars的内容,而不会对其进行求值。检索到 xVars 的内容并将其插入到主块中后,整个内容将通过封闭的

检查发生了什么的一个好技巧:省略封闭的求值()并查看日志。
然后,JMP 会在日志中打印“预处理”的表达式,而不对其进行求值。这样,用户就可以查看最终的表达式并查找错误:

如果一切如预期,只需添加求值()来评估表达式。