創建循環以在圖表中顯示參考線大家好,
我從 1 年開始使用 JMP15,但我才剛剛開始對腳本感興趣。
我想編寫一個腳本來根據表格在圖表中顯示參考線。
我有 2 個表:數據(我在其上運行腳本,以繪製 value=f(time))和日期,其中包含一列,其中的日期對應於我希望在圖表中具有的參考線。
這些表格附在我的帖子中。
這是我當前的腳本,根據表日期的第一個元素列日期顯示一個參考線。
ref1 = dates:name( "date" )[1];
Graph Builder(
Variables( X( :time ), Y( :value ),Page(:cat) ),
Elements( Points( X, Y, Legend( 4 ), Summary Statistic( "Mean" ) ) ),
SendToReport( Dispatch( {}, "time", ScaleBox( 2 ), {Add Ref Line( ref1, "Dotted", "Red", "", 2 )} ) )
);我想創建一個“For”循環來為表“日期”的每個值自動創建參考線。
這是我嘗試過的:
ref1 = dates:name( "date" )[1];
Graph Builder(
Variables( X( :time ), Y( :value ),Page(:cat) ),
Elements( Points( X, Y, Legend( 4 ), Summary Statistic( "Mean" ) ) ),
SendToReport( Dispatch( {}, "time", ScaleBox( 2 ),
{
For( i = 1, i <= N row( dates), i++,
f = dates [ i ];
Add Ref Line( f, "Dotted", "Blue", "", 2 )
);
})
);但是當我運行腳本時,沒有出現參考線。
我該如何解決這個問題?
最後一個問題:如果我不在圖形變量中添加“Page(:cat)”,則不會出現參考線...
謝謝您的幫助 !!
圖形腳本回复:創建一個循環以在圖表中顯示參考線歡迎來到討論社區!
這是添加參考線的一種方法

有關如何使用顯示樹來操作 JMP 輸出的文檔可在腳本索引中找到。
Names Default To Here( 1 );
dt = Data Table( "data" );
dates = Data Table( "dates" );
ref1 = dates:name( "date" )[1];
gb = Graph Builder(
Variables( X( :time ), Y( :value ), Page( :cat ) ),
Elements( Points( X, Y, Legend( 4 ), Summary Statistic( "Mean" ) ) ),
SendToReport(
Dispatch( {}, "time", ScaleBox( 2 ), {Add Ref Line( ref1, "Dotted", "Red", "", 2 )} )
)
);
// Add reference lines
For( i = 1, i <= N Rows( dates ), i++,
// Add for Cat = B
(Report( gb )[axisbox( 1 )]) << add ref line( dates:date[i], "Dotted", "Blue", "", 2 );
// Add for Cat = C
(Report( gb )[axisbox( 3 )]) << add ref line( dates:date[i], "Dotted", "Blue", "", 2 );
);
回复:創建一個循環以在圖表中顯示參考線謝謝吉姆的快速回复,真的很有幫助!
回复:創建一個循環以在圖表中顯示參考線這是一個不使用顯示樹的解決方案。
Names Default To Here( 1 );
dt = Data Table( "data" );
dts = Data Table( "dates" );
// Get the unique values of cat
summarize(cat_unique = by(dt:cat));
gb = dt << Graph Builder(
Show Control Panel( 0 ),
Variables( X( :time ), Y( :value ), Page( :cat ) ),
Elements( Points( X, Y, Legend( 4 ), Summary Statistic( "Mean" ) ) ),
);
// Add reference lines
for (c = 1, c <= nitems(cat_unique), c++,
scbox = c + 1;
for (i = 1, i <= nrows(dts), i++,
ref = dts:date[i];
gb << SendToReport(
Dispatch( {}, "time", ScaleBox( scbox ), {Add Ref Line( ref, "Dotted", "Red", "", 2 )} )
);
);
);