创建循环以在图表中显示参考线大家好,
我从 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 )} )
);
);
);