The syntax for the SendToReport argument is as follows (from the Scripting Index):
SendToReport( Dispatch( "Outline name", "Element name", Element type, command );
The second argument in the dispatch command ("Element Name") is used as an identifier to find the correct DisplayBox. For example, this argument would match the "helpKey" attribute when using a Dispatch command for a FrameBox. The element type argument tells JMP what type of attribute to look for (as it is different for different DisplayBoxes).
For a ScaleBox (as needed in this case), the element name argument refers to the "charID" attribute. Graph Builder creates multiple ScaleBoxes for various purposes, but the charID of "400" is assigned to the ScaleBox that is needed for sending messages such as Legend Model.
Below is an excerpt of the XML for a Graph Builder (created using the scripts farther down) that shows the five ScaleBoxes that were created. You will notice that one of the scale boxes has a charID of "400," which is the scale box we need to use for the Legend Model message.
<..truncated..>
<ScaleBox width="630" height="500" charID="height">
<ScaleBox width="630" height="500" charID="weight">
<ScaleBox width="630" height="500" charID="">
<ScaleBox width="630" height="500" charID="">
<ScaleBox width="630" height="500" charID="400">
<..truncated..>
</ScaleBox>
</ScaleBox>
</ScaleBox>
</ScaleBox>
</ScaleBox>
<..truncated..>
Another way to approach of using the Legend Model message is to send it directly to this ScaleBox. One way to reference this ScaleBox is using XPath as shown below. This method references the ScaleBox that has the charID of "400."
dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
gb = dt << Graph Builder(
Show Control Panel( 0 ),
Grid Transparency( 0 ),
Variables( X( :height ), Y( :weight ), Overlay( :sex ) ),
Elements( Points( X, Y, Legend( 1 ) ), Smoother( X, Y, Legend( 2 ) ) )
);
scalebox = gb << xpath("//ScaleBox[@charID=\!"400\!"]");
scalebox << Legend Model( 2, Properties( 1, {Line Color( 4 )} ) );
The below script does the same thing, but uses the SendToReport method instead.
dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
gb = dt << Graph Builder(
Show Control Panel( 0 ),
Grid Transparency( 0 ),
Variables( X( :height ), Y( :weight ), Overlay( :sex ) ),
Elements( Points( X, Y, Legend( 1 ) ), Smoother( X, Y, Legend( 2 ) ) ),
SendToReport(
Dispatch(
{},
"400",
ScaleBox,
{Legend Model( 2, Properties( 1, {Line Color( 4 )} ) )}
)
)
);
Thanks,
Justin