大家好,
我需要更改数据点标签位置。我的问题是我需要在表达式语句中定义新的标签位置(参见变量LabelPosText )。我知道在下面的示例中这没有必要,但我想让您免于阅读我的长代码,所以我向您展示了一个简化的示例。
我现在无法将变量LabelPosText的内容放入 Graph Builder 表达式部分(相应行标有//here I need help
)。我尝试了 Eval()、Eval Expr() 等的几种组合,但都没有起到作用。
非常感谢您的帮助!
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
Eval(
Parse(
"dt << New Script(\!"test script\!",
<BR /> //defining new label positions for some data points
Rows = dt << get rows where( :Sex == \!"F\!" );
LabelPosText = \!"\!";
For Each({row, idx}, Rows,
WeightValue = Column( dt, \!"weight\!")[row];
HeightValue = Column( dt, \!"height\!")[row];
LabelPosText = LabelPosText || \!"{\!"|| char(row-1) ||\!", -5, 12, \!"|| char(WeightValue) ||\!", \!"|| char(HeightValue) ||\!"}\!";
if(idx < N Items(Rows),
LabelPosText = LabelPosText || \!", \!"
)
);
Graph Builder(
Size( 528, 456 ),
Show Control Panel( 0 ),
Variables( X( :weight ), Y( :height ) ),
Elements( Points( X, Y, Legend( 5 ) ) ),
SendToReport(
Dispatch( {}, \!"Graph Builder\!", FrameBox,
{DispatchSeg(
Marker Seg( 1 ),
{Label Offset( LabelPosText ), //here I need help ;)
Set Force Labels( \!"Label by Row\!" )}
)}
)
)
)
)"
)
可以在里面计算它们。如果它们有可能在不同的表脚本运行之间发生变化,那么它们应该在里面,否则我会将它们移到外面并评估脚本中的值。
一般来说,我会避免使用 EvilParse (Eval(Parse()),因为它的调试非常困难,而且在我看来,几乎没有理由使用它。这看起来很复杂,但我会用类似下面的方法解决这个问题
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
// Label Offset has very annoying format to build as it isn't list with lists
// but just something with lists
table_script = Expr(
Names Default To Here(1);
Rows = Current Data Table() << get rows where(:Sex == "F");
offsets = Expr(Label Offset());
For Each({row, idx}, Rows,
WeightValue = :weight[row];
HeightValue = :height[row];
l = Eval List({row - 1, -5, 12, WeightValue, HeightValue});
Insert Into(offsets, l);
);
Eval(Substitute(
Expr(Graph Builder(
Size(528, 456),
Show Control Panel(0),
Variables(X(:weight), Y(:height)),
Elements(Points(X, Y, Legend(5))),
SendToReport(
Dispatch({}, "Graph Builder", FrameBox,
{DispatchSeg(
Marker Seg(1),
{_labeloffset_,
Set Force Labels("Label by Row")}
)}
)
)
)),
Expr(_labeloffset_), Name Expr(offsets)
));
);
Eval(EvalExpr(
dt << New Script("test script",
Expr(Name Expr(table_script));
);
));
您还可以将标签偏移移出图形生成器,并在构建图形生成器后将消息发送到图形生成器(我不确定这是否正确设置了“设置强制标签”)
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
// Label Offset has very annoying format to build as it isn't list with lists
// but just something with lists
table_script = Expr(
Names Default To Here(1);
Rows = Current Data Table() << get rows where(:Sex == "F");
offsets = Expr(Label Offset());
For Each({row, idx}, Rows,
WeightValue = :weight[row];
HeightValue = :height[row];
l = Eval List({row - 1, -5, 12, WeightValue, HeightValue});
Insert Into(offsets, l);
);
gb = Graph Builder(
Size(528, 456),
Show Control Panel(0),
Variables(X(:weight), Y(:height)),
Elements(Points(X, Y, Legend(5))),
SendToReport(
Dispatch({}, "Graph Builder", FrameBox,
{DispatchSeg(
Marker Seg(1),
{Set Force Labels("Label by Row")}
)}
)
)
);
ms = Report(gb)[FrameBox(1)] << Find Seg(MarkerSeg(1));
Eval(EvalExpr(Send(ms, Expr(Name Expr(offsets)))));
wait(0);
);
Eval(EvalExpr(
dt << New Script("test script",
Expr(Name Expr(table_script));
);
));
最终表格脚本应如下所示
Names Default To Here(1);
Rows = Current Data Table() << get rows where(:Sex == "F");
offsets = Expr(Label Offset());
For Each({row, idx}, Rows,
WeightValue = :weight[row];
HeightValue = :height[row];
l = Eval List({row - 1, -5, 12, WeightValue, HeightValue});
Insert Into(offsets, l);
);
gb = Graph Builder(
Size(528, 456),
Show Control Panel(0),
Variables(X(:weight), Y(:height)),
Elements(Points(X, Y, Legend(5))),
SendToReport(
Dispatch({}, "Graph Builder", FrameBox,
{DispatchSeg(Marker Seg(1), {Set Force Labels("Label by Row")})}
)
)
);
ms = Report(gb)[FrameBox(1)] << Find Seg(Marker Seg(1));
Eval(Eval Expr(ms << Expr(Name Expr(offsets))));
Wait(0);
以及从图形生成器获得的脚本
Graph Builder(
Size(528, 456),
Show Control Panel(0),
Variables(X(:weight), Y(:height)),
Elements(Points(X, Y, Legend(5))),
SendToReport(
Dispatch({}, "Graph Builder", FrameBox,
{DispatchSeg(
Marker Seg(1),
{Label Offset(
{8, -5, 12, 112, 60},
{0, -5, 12, 95, 59},
{9, -5, 12, 107, 61},
{1, -5, 12, 123, 61},
{10, -5, 12, 67, 56},
{2, -5, 12, 74, 55},
{3, -5, 12, 145, 66},
{4, -5, 12, 64, 52},
{15, -5, 12, 81, 61},
{16, -5, 12, 91, 62},
{17, -5, 12, 142, 65},
{18, -5, 12, 84, 63},
{19, -5, 12, 85, 62},
{27, -5, 12, 92, 62},
{28, -5, 12, 112, 64},
{34, -5, 12, 112, 65},
{35, -5, 12, 115, 60},
{37, -5, 12, 116, 62}
), Set Force Labels("Label by Row")}
)}
)
)
);
非常新,感谢这个信息 - 特别是没有标签,它真的很有用!!
对于标签偏移,我找不到很多文档 - 似乎没有供用户使用的功能?
有趣的:
- x /y 坐标似乎只是用于双重检查。这可以用来简化命令:
只需向 MALE 提供错误的值即可摆脱它们。
- 偏移使用什么坐标系?恒定偏移不会导致每个标签的恒定偏移。

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
LabelPosOffsets = Expr(Label Offset());
For Each row(
Insert Into(LabelPosOffsets,Eval List({row() - 1, -100,100,:weight+if( sex=="F", 0,1),:height}))
);
Eval (Eval Expr(Graph Builder(
Size( 528, 456 ),
Show Control Panel( 0 ),
Variables( X( :weight ), Y( :height ), Color( :sex ) ),
Elements( Points( X, Y, Legend( 5 ) ) ),
SendToReport(
Dispatch( {}, "Graph Builder", FrameBox,
{DispatchSeg(
Marker Seg( 1 ),
{ Expr(Name Expr(LabelPosOffsets) ), Set Force Labels( "Label by Row" )}
)}
)
)
)));