使用 JSL 以编程方式向现有绘图添加注释大家好,
在图形生成器中制作绘图后,我希望通过 JSL将一些元数据“精美打印”添加到我的绘图中。
下面是我希望使用 JSL 完成的两个示例:元数据 1 文本字段位于绘图区域中,元数据 2 文本字段位于图形底部的外部。在示例图中,我刚刚通过 GUI 中的注释工具添加了文本字段。然而,我很难弄清楚如何在 JSL 中实现这一点。
这是我在这里发表的第一篇文章 - 提前感谢您的帮助!

视窗回复:使用 JSL 以编程方式向现有绘图添加注释这是一些执行您指定操作的硬连线代码

Names Default To Here( 1 );
dt =
// Open Data Table: Big Class.jmp
// → Data Table( "Big Class" )
Open( "$SAMPLE_DATA/Big Class.jmp" );
gb = dt << Graph Builder(
Size( 528, 456 ),
Show Control Panel( 0 ),
Variables( X( :weight ), Y( :height ) ),
Elements( Points( X, Y, Legend( 3 ) ), Smoother( X, Y, Legend( 4 ) ) )
);
// To add text within the graph one way is to use "Add Graphics Script"
// to the graph
Report( gb )[Outline Box( 1 ), framebox( 1 )] <<
add graphics script(
xMin = Report( gb )[axisbox( 1 )] << get min;
yMin = Report( gb )[axisbox( 2 )] << get min;
Text Color( "red" );
Text(
Right Justified,
{xMin + 46, yMin + 1},
"Metadata1 " || Format( Today(), "yyyymmdd" ) || "/OwnerName"
);
Text( Right Justified, {xMin + 32, yMin + .1}, "path c:tmp/graph-01.jrp" );
);
// Add Outside of the graph
Report( gb )[Outline Box( 1 )] << Append(
V List Box(
Text Box( "Metadata1 " || Format( Today(), "yyyymmdd" ) || "/OwnerName" ),
Text Box( "path c:tmp/graph-01.jrp" )
)
);
回复:使用 JSL 以编程方式向现有绘图添加注释谢谢你,吉姆,这太快了!
这几乎让我达到了目标。现在我可以生成我想要的文本了。
但是,如果将以这种方式制作的图表保存为脚本,我会得到如下结果:
Graph Builder(
Size( 528, 456 ),
Show Control Panel( 0 ),
Variables( X( :weight ), Y( :height ) ),
Elements( Points( X, Y, Legend( 3 ) ), Smoother( X, Y, Legend( 4 ) ) ),
SendToReport(
Dispatch(
{},
"Graph Builder",
FrameBox,
{Add Graphics Script(
5,
Description( "" ),
xMin = Report( gb )[axisbox( 1 )] << get min;
yMin = Report( gb )[axisbox( 2 )] << get min;
Text Color( "red" );
Text(
Right Justified,
{xMin + 46, yMin + 1},
"Metadata1 " || Format( Today(), "yyyymmdd" ) || "/OwnerName"
);
Text(
Right Justified,
{xMin + 32, yMin + 0.1},
"path c:tmp/graph-01.jrp"
);
)}
)
)
)
如果我尝试运行该脚本,则会收到错误
>对象在访问或评估“Report(gb)[ /*###*/axisbox(1)]”时不可下标,Report(gb)[/*###*/axisbox(1)]
我认为这是有道理的,因为脚本中没有定义“gb”。有什么办法可以解决这个问题吗?
回复:使用 JSL 以编程方式向现有绘图添加注释您缺少指向 Graph Builder 实例的变量“gb”
gb = Graph Builder(
回复:使用 JSL 以编程方式向现有绘图添加注释嗯,这是真的,但是当我使用“保存脚本...到数据表”时,JMP 就是这样保存脚本的。
但是我从这里找到了使用 Eval 和 EvalExpr 的解决方案:
https://community.jmp.com/t5/Discussions/GraphBuilder-gt-FrameBox-lt-lt-Add-Graphics-Script-V-Line-x-y1/td-p/366991
这样我就可以完成所有工作了:
Names Default To Here( 1 );
dt =
// Open Data Table: Big Class.jmp
// → Data Table( "Big Class" )
Open( "$SAMPLE_DATA/Big Class.jmp" );
gb = dt << Graph Builder(
Size( 528, 456 ),
Show Control Panel( 0 ),
Variables( X( :weight ), Y( :height ) ),
Elements( Points( X, Y, Legend( 3 ) ), Smoother( X, Y, Legend( 4 ) ) )
);
yMin = Report( gb )[axisbox( 1 )] << get min;
yMin = Report( gb )[axisbox( 2 )] << get min;
//I need the values "hard-coded"" in the new graphics script to be added => hence i
//need to use the Eval(EvalExpr( .. )) trick from
//https://community.jmp.com/t5/Discussions/GraphBuilder-gt-FrameBox-lt-lt-Add-Graphics-Script-V-Line-x-y1/td-p/366991
Eval(EvalExpr(
Report( gb )[Outline Box( 1 ), framebox( 1 )] <<
add graphics script(
Text Color( "red" );
Text( {expr(xMin),expr(yMin)}, "path c:tmp/graph-01.jrp" );
)
));
回复:使用 JSL 以编程方式向现有绘图添加注释您还可以对 Jim 的脚本进行一些修改,并使用 X Origin 和 Y Origin 来设置位置
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
gb = dt << Graph Builder(
Size(528, 456),
Show Control Panel(0),
Variables(X(:weight), Y(:height)),
Elements(Points(X, Y, Legend(3)), Smoother(X, Y, Legend(4)))
);
Report(gb)[FrameBox(1)] << Add Graphics Script(
Text Color("Red");
Text({X Origin(), Y Origin()},
"Metadata1 " || Format(Today(), "yyyymmdd") || "/OwnerName\!Npath c:tmp/graph-01.jrp"
);
);