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

How can I script a moving Y variable for the graph builder ?

Hi all,

I am doing a graph builder with a moving Y variables, the output of the graph will appear like this:

image.png

But, I am struggling to script the Y axis in JSL.  How can I do so ?

For( i = 1, i <= N Items(  NamesList ), i++,

obj = Graph Builder(
	Size( 534, 464 ),
	Show Control Panel( 0 ),
	Variables(
		X( :TETEST_MONTH ),
		X( :TETEST_WEEK, Position( 1 ) ),
		Y( :Name ("Y")) , // how do I insert the moving Y variable here ?
	    Y( :Name ("Y")), // how do I insert the moving Y variable here ?
		Color( :TETEST_MONTH )
	),
	Elements( Position( 1, 1 ), Histogram( X( 2 ), X( 1 ), Y, Legend( 14 ) ) ),
	Elements(
		Position( 1, 2 ),
		Box Plot( X( 2 ), X( 1 ), Y, Legend( 16 ) ),
		Line( X( 2 ), X( 1 ), Y, Legend( 17 ) )
	),
	SendToReport( Dispatch( {}, "400", LegendBox, {Set Title( "" )} ) )
));
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How can I script a moving Y variable for the graph builder ?

My error......get rid of all of the gb[i] references and change them to just gb.  

Jim

View solution in original post

6 REPLIES 6
txnelson
Super User

Re: How can I script a moving Y variable for the graph builder ?

Assuming that "NamesList" contains the Y columns you want to use as your Y columns, then replace

     :Names( "Y" )

with:

     as Column( NamesList[i] )

Jim

Re: How can I script a moving Y variable for the graph builder ?

Thanks Jim.

But I have not idea why this error kept prompting me during debugging. 

image.png

 

For( i = 1, i <= N Items(  numericColNamesList ), i++,

gb = dt << Graph Builder(
	Size( 900, 850 ),
	Show Control Panel( 0 ),
	Variables(
		X( :MONTH ),
		X( :WEEK, Position( 1 ) ),
		Y( Column( numericColNamesList[i])) ,
	    Y( Column( numericColNamesList[i])) ,
		Color( :MONTH )
	),
	Elements( Position( 1, 1 ), Histogram( X( 2 ), X( 1 ), Y, Legend( 14 ) ) ),
	Elements(
		Position( 1, 2 ),
		Box Plot( X( 2 ), X( 1 ), Y, Legend( 16 ) ),
		Line( X( 2 ), X( 1 ), Y, Legend( 17 ) )
	),
	SendToReport( Dispatch( {}, "400", LegendBox, {Set Title( "" )} ) )
));


	Report(gb[1])  << Save Presentation( "C:\Users\Ann Ann\1.pptx" );
For( i = 2, i <= N Items( numericColNamesList ), i++,
	 Report (gb[i] << Save Presentation( "C:\Users\Ann Ann\1.pptx", Append )
));

Open( "C:\Users\Ann Ann\1.pptx" );

//wait(0);

//obj << close window();

 

txnelson
Super User

Re: How can I script a moving Y variable for the graph builder ?

You are using 

    gb = dt << Graph Builder(.........

for each execution of the Graph Builder Platform.  It is not a vector of values.  Each time you run the Graph Builder script, you are creating a new value for the variable "gb". That is, the pointer to the last instance of Graph Builder is moved to point to the new instance of Graph Builder.  There is not a gb[1], gb[2], etc. the way you have the code setup. 

One way to overcome this, is to move the Save Presentation area of code, inside the inititial For() loop. 

Another way to solve this is in the initial For() Loop,  save the values of "gb" into a list after it's creation.  Then, point to the elements in the list in the second For() Loop, instead of gb[i] etc.

 

For( i = 1, i <= N Items( numericColNamesList ), i++, 

	gb = dt << Graph Builder(
		Size( 900, 850 ),
		Show Control Panel( 0 ),
		Variables(
			X( :MONTH ),
			X( :WEEK, Position( 1 ) ),
			Y( Column( numericColNamesList[i] ) ),
			Y( Column( numericColNamesList[i] ) ),
			Color( :MONTH )
		),
		Elements( Position( 1, 1 ), Histogram( X( 2 ), X( 1 ), Y, Legend( 14 ) ) ),
		Elements(
			Position( 1, 2 ),
			Box Plot( X( 2 ), X( 1 ), Y, Legend( 16 ) ),
			Line( X( 2 ), X( 1 ), Y, Legend( 17 ) )
		),
		SendToReport( Dispatch( {}, "400", LegendBox, {Set Title( "" )} ) )
	);
	
	If( i == 1,
		Report( gb ) << Save Presentation( "C:\Users\Ann Ann\1.pptx" ),
		Report( gb[i] << Save Presentation( "C:\Users\Ann Ann\1.pptx", Append ) )
	);
);


Open( "C:\Users\Ann Ann\1.pptx" );
Jim

Re: How can I script a moving Y variable for the graph builder ?

Thanks, Jim. But I still ecounter error. I guess something may not right with my segmentation. 

 

/* Open a sample data table */
dt = Open( "C:\Users\1.jmp", invisible );

// Find the Y Columns
numericColNamesList = dt << get column names( string, numeric );

For( i = N Items( numericColNamesList ), i >= 1, i--,
	If(
		Not(
			Is Missing( Num( Word( 1, numericColNamesList[i], ":" ) ) ) == 0 &
			Word( 2, numericColNamesList[i], ":" ) != ""
		),
		numericColNamesList = Remove( numericColNamesList, i, 1 )
	)
);

// Run the Variance Charts
// With dynamic Y columns and fixed X columns

Fo( i = 1, i <= N Items( numericColNamesList ), i++, 

	gb = dt << Graph Builder(
	Invisible,
	Size( 752, 508 ),
	Show Control Panel( 0 ),
	Show Legend( 0 ),
	Variables(
		X( :Month ),
		Y( Column ( numericColNamesList[i] ) ),
		Overlay( :Month )
	),
	Elements(
		Box Plot(
			X,
			Y,
			Legend( 15 ),
			Jitter( 0 ),
			Outliers( 0 ),
			Box Style( "Solid" )
		),
		Histogram( X, Y, Legend( 12 ) )
	));
		
	gb = LIST (gb[i]);
	
	If( i == 1,
		Report( gb ) << Save Presentation( "C:\Users\Ann Ann\1.pptx" ),
		Report( gb[i] << Save Presentation( "C:\Users\Ann Ann\1.pptx", Append ) )
	));
	

 

txnelson
Super User

Re: How can I script a moving Y variable for the graph builder ?

My error......get rid of all of the gb[i] references and change them to just gb.  

Jim

Re: How can I script a moving Y variable for the graph builder ?

Thank you, Jim. It is working wonderfully now.