cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
newbie_alex
Level III

Graph Builder, how to change the color of an element, and information about SendToReport syntax

Hello,

 

I create a graph with dynamic content (number of variables is determined at run time).

 

I would like to change to change several things after setting up the graph builder, e.g. assign a new color. The reason for doing it afterwards is because, I do not know the changes before executing other parts of my script that I cannot run earlier.

 

I have simplified my basic problem to this example:

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

gb = Graph Builder(
	Automatic Recalc( 0 ),
	Variables( X( :age ), Y( :height ) ),
	Elements( Points( X, Y ), Smoother( X, Y ) )
);

// do some other stuff incl. addition or removal of variables to gb

// how do I *MODIFY* the color of Points, Smoother here or add a Line Plot?

I know the position of the variables in the graph if that helps (1,1 in the example above).

 

Cheers,

Alex

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
ian_jmp
Staff

Re: how to change the color of a line

Just do it interactively, and then inspect the code that JMP generates for you. Adapting your example:

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

gb = Graph Builder(
	Automatic Recalc( 0 ),
	Variables( X( :age ), Y( :height ) ),
	Elements( Points( X, Y, Legend( 1 ) ), Smoother( X, Y, Legend( 2 ) ) )
);

// Add 'weight'
Wait(2);
gbb = Report( gb )[Graph Builder Box( 1 )];
upper_graph_inner_pos = 2;
gbb << Add Variable({Column( "weight" ), Role( "Y" ), Position( 1 ), Inner Position( upper_graph_inner_pos )});

// Change the colour of the points and smoother for 'weight' to green
Wait(2);
gb << SendToReport( Dispatch({}, "400", ScaleBox, {Legend Model( 2, Properties( 1, {Line Color( 4 )} ) )} ) );

Regarding the less important question, you can look in 'Help > Books > Scripting Guide' which often gives some pointers.

View solution in original post

Re: how to change the color of a line

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

View solution in original post

10 REPLIES 10
newbie_alex
Level III

Re: how to change the color of a line

here is a better example. how do I change the color of the points and the smoother for weight in this one?

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

gb = Graph Builder(
	Automatic Recalc( 0 ),
	Variables( X( :age ), Y( :height ) ),
	Elements( Points( X, Y, Legend( 1 ) ), Smoother( X, Y, Legend( 2 ) ) )
);

gbb = Report( gb )[Graph Builder Box( 1 )];
upper_graph_inner_pos = 2;
gbb << Add Variable(
	{Column( "weight" ), Role( "Y" ), Position( 1 ), Inner Position( upper_graph_inner_pos )}
);


gb << SendToReport(
	Dispatch( {}, "400", ScaleBox, {Legend Model( 1, Properties( 0, {Line Color( RGB color(31,119,180) ), Fill Color( 0 )} ) )} )
);

less important questions:

What does "400" mean in this context?

 

DC1123
Level II

Re: how to change the color of a line

I have had similar questions but never got answers. It seems that JMP expert in this forum shun this question or do not encourage JMP user  to know this deeper.

ian_jmp
Staff

Re: how to change the color of a line

Just do it interactively, and then inspect the code that JMP generates for you. Adapting your example:

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

gb = Graph Builder(
	Automatic Recalc( 0 ),
	Variables( X( :age ), Y( :height ) ),
	Elements( Points( X, Y, Legend( 1 ) ), Smoother( X, Y, Legend( 2 ) ) )
);

// Add 'weight'
Wait(2);
gbb = Report( gb )[Graph Builder Box( 1 )];
upper_graph_inner_pos = 2;
gbb << Add Variable({Column( "weight" ), Role( "Y" ), Position( 1 ), Inner Position( upper_graph_inner_pos )});

// Change the colour of the points and smoother for 'weight' to green
Wait(2);
gb << SendToReport( Dispatch({}, "400", ScaleBox, {Legend Model( 2, Properties( 1, {Line Color( 4 )} ) )} ) );

Regarding the less important question, you can look in 'Help > Books > Scripting Guide' which often gives some pointers.

newbie_alex
Level III

Re: how to change the color of a line

Hello Ian,

 

thank you for the great example.

 

Would you please point me to the part of the scripting guide that contains information about the legend model syntax, the meaning of the value "400"?

 

I have search for the words "legend model" - no hits. 400 had several hits but I could not identify something relevant.

 

Thank you for your help!

 

Cheers,

Alex

pmroz
Super User

Re: how to change the color of a line

Not all of the "inner" syntax of graph builder is documented.  When it comes to GB I do the following:

 

Create a graph that looks exactly like what I want, including graph type, symbols, colors, lines, etc. 

Click the little red triangle to get the JSL code

Embed the JSL code in my script

 

Basically I let GB do the heavy lifting and then use the code it generates.

 

 

newbie_alex
Level III

Re: how to change the color of a line

I do the same but now that I do see the generated code, I need to be able to understand it.

 

I could not find documentation for Legend Model and neither for "400".

 

That is why I was asking for help and would highly appreciate feedback.

pmroz
Super User

Re: how to change the color of a line

This is a great request for JMP development, namely to document the inner workings of graph builder.

Re: how to change the color of a line

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
newbie_alex
Level III

Re: how to change the color of a line

Thank you for the feedback.

 

Would you please also explain the Legend Model syntax?