JMP软件的JSL(非javascript) 添加画线:在右侧的图:"总"的左端点与右端点添加连线、...

Created on: June 22, 2025

Answered using O3 by Chat01

Question

JMP软件的JSL(非javascript)
添加画线:在右侧的图:"总"的左端点与右端点添加连线、(虚线)
p1=d3<< Graph Builder(Size(1308,771),Variables(X(:日期),Y(:close),Y(:总,Position(1),Side("右侧")),Size(:行)),Elements(Points(X,Y(1),Legend(15)),Points(X,Y(2),Legend(16))),SendToReport(Dispatch({},"日期",ScaleBox,{Min(-1),Max(r0+2),Inc(1),Minor Ticks(0)}),Dispatch({},"close",ScaleBox,{Min(小1),Max(大1),Inc(200),Minor Ticks(1)}),Dispatch({},"总",ScaleBox,{Min(小2),Max(大2),Inc(50),Minor Ticks(4)})));

Thought

Referring to customization for Add Graphics

I’m considering referencing the "Customizing Graphs" page to explain Add Graphics script customizations, but I can’t access that. Perhaps I can look at the "Scripting Graphs" documentation, which should help. This includes information on drawing lines and specifying line types. Specifically, the page on line styles mentions how to control line types, including dashed lines, which will be useful for explaining how to integrate dashed lines in my scripts!

Crafting the Final Answer

The solution involves integrating modifications into the existing graph script using "Draw Lines" and "Specify Line Types" documentation. Here's how we can incorporate it:

  • First, the script uses NamesDefaultToHere(1) and the current data table.
  • We retrieve the earliest and latest

Thought for 1m 9s

Answer

下面给出一种最小改动的做法:保留你现有的 Graph Builder 脚本,只在图生成后用 Add Graphics Script 往 FrameBox 里“补上一条虚线”。整段脚本可以直接复制-粘贴到 JSL 编辑器中运行。

jsl
Names Default To Here(1); // 让局部变量更安全 dt = Current Data Table(); // 假设 d3 就是当前数据表 /* ----------1. 先照你原来的方式建图---------- */ p1 = d3 << Graph Builder( Size(1308, 771), Variables( X(:日期), Y(:close), Y(:总, Position(1), Side("右侧")), Size(:行) ), Elements( Points(X, Y(1), Legend(15)), Points(X, Y(2), Legend(16)) ), SendToReport( Dispatch({}, "日期", ScaleBox, {Min(-1), Max(r0 + 2), Inc(1), Minor Ticks(0)}), Dispatch({}, "close", ScaleBox, {Min(小1), Max(大1), Inc(200), Minor Ticks(1)}), Dispatch({}, "总", ScaleBox, {Min(小2), Max(大2), Inc(50), Minor Ticks(4)}) ) ); /* ----------2. 计算“总”列最左、最右端点的坐标---------- */ x1 = Col Min(dt:日期); // 最早日期 row1 = dt << Get Rows Where(:日期 == x1); // 该日期所在的行号 y1 = dt:总[row1[1]]; // “总”的起点 Y 值 x2 = Col Max(dt:日期); // 最晚日期 row2 = dt << Get Rows Where(:日期 == x2); y2 = dt:总[row2[1]]; // “总”的终点 Y 值 /* ----------3. 向 Graph Builder 的 FrameBox 添加虚线---------- */ rep = p1 << Report; // 报表句柄 rep[FrameBox(1)] // 对应主坐标系(包含左右两条 Y 轴) << Add Graphics Script( Pen Size(2); // 线宽,可按需调整 Line Style("Dashed"); // 把线型改成虚线 [jmp.com](https://www.jmp.com/support/help/en/18.1/jmp/specify-line-types-in-jmp-graphs.shtml) Line({x1, y1}, {x2, y2}); // 连接两端点 [jmp.com](https://www.jmp.com/support/help/en/18.1/jmp/draw-lines.shtml) ); /* ----------脚本结束---------- */

说明与要点

  1. 取端点坐标

    • Col Min/Col Max 给出 日期 列的最小和最大值。
    • Get Rows Where 找到对应行,再取出该行在 列上的数值,就是虚线的 Y 坐标。
  2. 为什么用 Add Graphics Script

    • 这样不会影响已有的元素,只是在渲染完毕后往 FrameBox 里画一条额外的线。
    • 线在图坐标系里绘制,因此无论缩放或改变轴范围都能跟着移动。
  3. 虚线的设置

    • Line Style("Dashed")(也可写 Line Style(2))即可把线型切换成虚线;JMP 帮助文档给出了可用名称/编号 0–4 的对照表。jmp.com
  4. 如果有多图 / 多 FrameBox

    • 默认单图 FrameBox(1) 就行;若你做 Facet 或 Page By,需按实际 FrameBox 编号修改。
  5. 可选的颜色或更多样式

    • Add Graphics Script 里再加 Pen Color("red");Pen Transparency(0.3); 等即可。

运行后,你会看到右侧 Y 轴对应的“总”曲线,在最左与最右的两个点之间,多了一条虚线连线,效果与手动在界面里画线完全一致,但能随脚本自动更新。

Share this Q&A