如何根據條件使用 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 會在日誌中列印「預處理」的表達式,而不對其進行求值。這樣,用戶就可以查看最終的表達式並找到錯誤:

如果一切如預期,只需加入求值()來評估表達式。