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
DMR
DMR
Level V

Updating the Graph Builder's Element statement

Hi - I want to change the style of the Graph Builder's box-and-whisker plot to a plot of points from within a JSL script. The Graph Builder initially includes an Elements statement that looks like this:

				Elements( Box Plot( Y, Legend( 9 ) ) ),

 

I therefore want to modify that statement from within JSL to:

 

				Elements( Points( Y, Legend( 9 ) ) ),

 

I've found the << Add Element, << Update Element and << Remove Element commands for the GraphBuilderBox within the Scripting Index, but I can't work out how to apply them to achieve the effect I want. The example given in the Index (adding a regression line) doesn't directly relate to my situation, but I'm guessing that I need something like the following, where gb is my Graph Builder object:

report(gb)[GraphBuilderBox(1)] << Update Element(1, 1, 1, {Type("Points"), Y})

 

This evidently isn't right however - so I just need an example to show me what the correct syntax ought to be. Can anyone help me with this, please?

 

Many thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
julian
Community Manager Community Manager

Re: Updating the Graph Builder's Element statement

I see just what your issue is now. Since you're using an X Grouping, and not an actual X variable, the indexing for the elements isn't standard. As per the docs:

obj << Get Element(xposition, yposition, i )

But, with an X Grouping, rather than an X, it seems that the first element isn't accessible with (1,1,1), (0,1,1), (.,1,1) or anything else I've tried.  So, here's what I came up with: temporarily define an X variable so you can access the element, and then remove the X variable once you've made the changes you need. I find it entirely inelegant, but it works. I'll try to find out if there is a proper way to access the elements when no X is defined so you don't need this workaround.  

 

Open("$SAMPLE_DATA/Big Class.jmp");

gb = Graph Builder(
	Variables( Y( :height ), Group X( :sex ) ),
	Elements( Box Plot( Y, Legend( 10 ) ) )
	);

wait( 1 );

gbb = Report( gb )[Graph Builder Box( 1 )];

//define an X temporarily
gbb << Add Variable( {:age, Role( "X" )} );

gbb << Remove Element(1, 1, 1);
gbb << Add Element(1, 1, {Type( "Points" ), X, Y, Legend( 5 )});

//remove the X
gbb << Remove Variable( {:age, Role( "X" )} );

 

View solution in original post

4 REPLIES 4
julian
Community Manager Community Manager

Re: Updating the Graph Builder's Element statement

Hi @DMR,

Update Element() will change the properties of an existing element, but as far as I know will not allow you to change the type of element it is. Try deleting the existing element and adding a new one. Example below. 

Hope this helps!

@julian

 

Open("$SAMPLE_DATA/Big Class.jmp");

gb = Graph Builder(
	Size( 528, 448 ),
	Show Control Panel( 0 ),
	Variables( X( :age ), Y( :height ) ),
	Elements( Box Plot( X, Y, Legend( 4 ) ) )
);

Wait(1);

gbb = Report( gb )[Graph Builder Box( 1 )];

gbb << Remove Element(1, 1, 1);
gbb << Add Element(1, 1, {Type( "Points" ), X, Y, Legend( 5 )});

 

 

DMR
DMR
Level V

Re: Updating the Graph Builder's Element statement

Hi Julian,

I'm closer to understanding the problem now, but unfortunately I'm still not quite there.  The difference between my situation and your example is that I'm using a discrete grouping variable instead of a continuous X variable: the following variation of your script illustrates the issue:

Open("$SAMPLE_DATA/Big Class.jmp");

gb = Graph Builder(
	Variables( Y( :height ), Group X( :sex ) ),
	Elements( Box Plot( Y, Legend( 10 ) ) )
	);

wait( 1 );

gbb = Report( gb )[Graph Builder Box( 1 )];

// How do I modify the following two lines to replace the Box Plot above by Points?

gbb << Remove Element(1, 1, 1);
gbb << Add Element(1, 1, {Type( "Points" ), X, Y, Legend( 5 )});

 

If you can just show me how to modify the final two lines, the problem will be solved.

julian
Community Manager Community Manager

Re: Updating the Graph Builder's Element statement

I see just what your issue is now. Since you're using an X Grouping, and not an actual X variable, the indexing for the elements isn't standard. As per the docs:

obj << Get Element(xposition, yposition, i )

But, with an X Grouping, rather than an X, it seems that the first element isn't accessible with (1,1,1), (0,1,1), (.,1,1) or anything else I've tried.  So, here's what I came up with: temporarily define an X variable so you can access the element, and then remove the X variable once you've made the changes you need. I find it entirely inelegant, but it works. I'll try to find out if there is a proper way to access the elements when no X is defined so you don't need this workaround.  

 

Open("$SAMPLE_DATA/Big Class.jmp");

gb = Graph Builder(
	Variables( Y( :height ), Group X( :sex ) ),
	Elements( Box Plot( Y, Legend( 10 ) ) )
	);

wait( 1 );

gbb = Report( gb )[Graph Builder Box( 1 )];

//define an X temporarily
gbb << Add Variable( {:age, Role( "X" )} );

gbb << Remove Element(1, 1, 1);
gbb << Add Element(1, 1, {Type( "Points" ), X, Y, Legend( 5 )});

//remove the X
gbb << Remove Variable( {:age, Role( "X" )} );

 

DMR
DMR
Level V

Re: Updating the Graph Builder's Element statement

Inelegant it may be, but it works - and ultimately that's all that matters!

 

Many thanks.