使用 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"
);
);