cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
New to using JMP? Hit the ground running with the Early User Edition of Discovery Summit. Register now, free of charge.
Register for our Discovery Summit 2024 conference, Oct. 21-24, where you’ll learn, connect, and be inspired.
Choose Language Hide Translation Bar
neelsrejan
Level III

Empty window when trying to append variability charts through for loop

Hi all, 

 

I have a piece of code that is working as intended below. But the problem is the repetition of code makes for a unnecessarily long 500 lines of code where a for loop through substitution in theory should be able to function to save lines of code. 

old win = New Window( "Old Win", vlis old = V List Box() );
df movies = Open("C:\Program Files\JMP\JMP\18\Samples\Data\Movies.jmp");

df action = df movies << Subset( Columns(), Rows(), Output Table Name( "df action" ));
Column(  df action, "Rating" ) << Set Property( "Value Colors", {"R" = 0} );
color_or_not = 1;
df action << Select Where(
	Or(
		!Contains( :Type, "Action" ),
		Contains( :Rating, "13" )
	)
) << Exclude;
df action << Delete Rows;

action lbx = V List Box(
	If(color_or_not == 1,
		vc action = df action << Variability Chart(
			Y( :Year ),
			X( :Movie ),
			Show Range Bars( 0 ),
			Show Cell Means( 0 ),
			Std Dev Chart( 0 ),
			Points Jittered( 1 ),
			Title( "Variability chart for Action" ),
			SendToReport(
				Dispatch(
					{"Variability Chart for Signal"},
					"2",
					ScaleBox,
					{Min( -50 ), Add Ref Line( 0, "Dotted", "Medium Light Gray", "", 1 ),
					Add Ref Line( 1999, "Dotted", "Medium Light Green", "1999", 1 )}
				),
				Dispatch(
					{""},
					"Variability Chart",
					FrameBox,
					{Row Legend(
						Rating,
						Color( 1 ),
						Color Theme( "" ), 
						Marker( 0 ),
						Marker Theme( "" ),
						Continuous Scale( 0 ),
						Reverse Scale( 0 ),
						Excluded Rows( 0 )
					)}
				);
			);
		);
	,	
		vc action = df action << Variability Chart(
			Y( :Year ),
			X( :Movie ),
			Show Range Bars( 0 ),
			Show Cell Means( 0 ),
			Std Dev Chart( 0 ),
			Points Jittered( 1 ),
			Title( "Variability chart for Action" ),
			SendToReport(
				Dispatch(
					{"Variability Chart for Signal"},
					"2",
					ScaleBox,
					{Min( -50 ), Add Ref Line( 0, "Dotted", "Medium Light Gray", "", 1 ),
					Add Ref Line( 1999, "Dotted", "Medium Light Green", "1999", 1 )}
				);
			);
		);	
	);
);
vlis old << Append( action lbx );

df comedy = df movies << Subset( Columns(), Rows(), Output Table Name( "df comedy" ));
Column(  df comedy, "Rating" ) << Set Property( "Value Colors", {"R" = 0} );
df comedy << Select Where(
	Or(
		!Contains( :Type, "Comedy" ),
		Contains( :Rating, "13" )
	)
) << Exclude;
df comedy << Delete Rows;

comedy lbx = V List Box(
	If(color_or_not == 1,
		vc comedy = df comedy << Variability Chart(
			Y( :Year ),
			X( :Movie ),
			Show Range Bars( 0 ),
			Show Cell Means( 0 ),
			Std Dev Chart( 0 ),
			Points Jittered( 1 ),
			Title( "Variability chart for Comedy" ),
			SendToReport(
				Dispatch(
					{"Variability Chart for Signal"},
					"2",
					ScaleBox,
					{Min( -50 ), Add Ref Line( 0, "Dotted", "Medium Light Gray", "", 1 ),
					Add Ref Line( 2000, "Dotted", "Medium Light Green", "2000", 1 )}
				),
				Dispatch(
					{""},
					"Variability Chart",
					FrameBox,
					{Row Legend(
						Rating,
						Color( 1 ),
						Color Theme( "" ), 
						Marker( 0 ),
						Marker Theme( "" ),
						Continuous Scale( 0 ),
						Reverse Scale( 0 ),
						Excluded Rows( 0 )
					)}
				);
			);
		);
	,	
		vc comedy = df comedy << Variability Chart(
			Y( :Movie ),
			X( :Year ),
			Show Range Bars( 0 ),
			Show Cell Means( 0 ),
			Std Dev Chart( 0 ),
			Points Jittered( 1 ),
			Title( "Variability chart for Comedy" ),
			SendToReport(
				Dispatch(
					{"Variability Chart for Signal"},
					"2",
					ScaleBox,
					{Min( -50 ), Add Ref Line( 0, "Dotted", "Medium Light Gray", "", 1 ),
					Add Ref Line( 2000, "Dotted", "Medium Light Green", "2000", 1 )}
				);
			);
		);	
	);
);
vlis old << Append( comedy lbx );

df family = df movies << Subset( Columns(), Rows(), Output Table Name( "df family" ));
Column(  df family, "Rating" ) << Set Property( "Value Colors", {"R" = 0} );
df family << Select Where(
	Or(
		!Contains( :Type, "Family" ),
		Contains( :Rating, "13" )
	)
) << Exclude;
df family << Delete Rows;

family lbx = V List Box(
	If(color_or_not == 1,
		vc family = df family << Variability Chart(
			Y( :Year ),
			X( :Movie ),
			Show Range Bars( 0 ),
			Show Cell Means( 0 ),
			Std Dev Chart( 0 ),
			Points Jittered( 1 ),
			Title( "Variability chart for Family" ),
			SendToReport(
				Dispatch(
					{"Variability Chart for Signal"},
					"2",
					ScaleBox,
					{Min( -50 ), Add Ref Line( 0, "Dotted", "Medium Light Gray", "", 1 ),
					Add Ref Line( 1995, "Dotted", "Medium Light Green", "1995", 1 )}
				),
				Dispatch(
					{""},
					"Variability Chart",
					FrameBox,
					{Row Legend(
						Rating,
						Color( 1 ),
						Color Theme( "" ), 
						Marker( 0 ),
						Marker Theme( "" ),
						Continuous Scale( 0 ),
						Reverse Scale( 0 ),
						Excluded Rows( 0 )
					)}
				);
			);
		);
	,	
		vc family = df family << Variability Chart(
			Y( :Movie ),
			X( :Year ),
			Show Range Bars( 0 ),
			Show Cell Means( 0 ),
			Std Dev Chart( 0 ),
			Points Jittered( 1 ),
			Title( "Variability chart for Family" ),
			SendToReport(
				Dispatch(
					{"Variability Chart for Signal"},
					"2",
					ScaleBox,
					{Min( -50 ), Add Ref Line( 0, "Dotted", "Medium Light Gray", "", 1 ),
					Add Ref Line( 2000, "Dotted", "Medium Light Green", "2000", 1 )}
				);
			);
		);	
	);
);
vlis old << Append( family lbx );

I have now tried to use my understanding of jmp substitution of expressions to make this for loop and can see in the log that the data tables are properly subsetted but I am not able to append the V List Box to the window as the code above is able to do without any issue. Any help to get the for loop to work as above would be greatly appreciated. Thanks!

Clear Globals();
Clear Log();

df movie = Open("C:\Program Files\JMP\JMP\18\Samples\Data\Movies.jmp");

color_or_not = 1;

df action = df movie << Subset( Columns(), Rows(), Output Table Name( "df action" ), Invisible );
df comedy = df movie << Subset( Columns(), Rows(), Output Table Name( "df comedy" ), Invisible );
df family = df movie << Subset( Columns(), Rows(), Output Table Name( "df family" ), Invisible );


new win = New Window( "New Win", vlis = V List Box() );

df list = {df action, df comedy, df family};
to remove one = {"Action", "Comedy", "Family"};
to remove two = {"13", "13", "13"};
names = {"Action", "Comedy", "Family"};
ref val = {1999, 2000, 1995};
ref line = {"1999", "2000", "1995"};

for (i = 1, i<=3, i++,
	Eval(
		Substitute(
			Expr(
				Column(  _df list_ , "Rating" ) << Set Property( "Value Colors", {"R" = 0} );
				_df list_ << Select Where(
					Or(
						!Contains( :"Type", _to remove one_ ),
						Contains( :"Rating", _to remove two_ )
					)
				) << Exclude;
				_df list_ << Delete Rows;
			),
			Expr( _df list_ ), df list[i],
			Expr( _to remove one_ ), to remove one[i],
			Expr( _to remove two_ ), to remove two[i],
		);
	);
	If(color_or_not == 1,
		Substitute(
			Expr(
				graph = V List Box(
					vc = _df list_ << Variability Chart(
						Y( :Year ),
						X( :Movie ),
						Show Range Bars( 0 ),
						Show Cell Means( 0 ),
						Std Dev Chart( 0 ),
						Points Jittered( 1 ),
						Title( "Variability chart for " || _names_ ),
						SendToReport(
							Dispatch(
								{"Variability Chart for Signal"},
								"2",
								ScaleBox,
								{Min( -50 ), Add Ref Line( 0, "Dotted", "Medium Light Gray", "", 1 ),
								Add Ref Line( _ref val_ , "Dotted", "Medium Light Green", _ref line_ , 1 )}
							),
							Dispatch(
								{""},
								"Variability Chart",
								FrameBox,
								{Row Legend(
									Rating,
									Color( 1 ),
									Color Theme( "" ), 
									Marker( 0 ),
									Marker Theme( "" ),
									Continuous Scale( 0 ),
									Reverse Scale( 0 ),
									Excluded Rows( 0 )
								)}
							);
						);
					);
				);
				vlis << Append( graph );		
			),
			Expr( _df list_ ), df list[i],
			Expr( _names_ ), names[i],
			Expr( _ref val_ ), ref val[i],
			Expr( _ref line_ ), ref line[i] 
		);
	,	
		Substitute(
			Expr(
				graph = V List Box(
					vc = _df list_ << Variability Chart(
						Y( :Year ),
						X( :Movie  ),
						Show Range Bars( 0 ),
						Show Cell Means( 0 ),
						Std Dev Chart( 0 ),
						Points Jittered( 1 ),
						Title( "Variability chart for " || _names_ ),
						SendToReport(
							Dispatch(
								{"Variability Chart for Signal"},
								"2",
								ScaleBox,
								{Min( -50 ), Add Ref Line( 0, "Dotted", "Medium Light Gray", "", 1 ),
								Add Ref Line( _ref val_ , "Dotted", "Medium Light Green", _ref line_ , 1 )}
							);
						);
					);
				);
				vlis << Append( graph );		
			),
			Expr( _df list_ ), df list[i],
			Expr( _names_ ), names[i],
			Expr( _ref val_ ), ref val[i],
			Expr( _ref line_ ), ref line[i]  
		);	
	);
);
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Empty window when trying to append variability charts through for loop

You left out the Eval() function in the Eval(Substitute(Expr))) processing

Names Default To Here( 1 );
Clear Globals();
Clear Log();

df movie = Open( "$SAMPLE_DATA\Movies.jmp" );

color_or_not = 1;

df action = df movie << Subset( Columns(), Rows(), Output Table Name( "df action" ), Invisible );
df comedy = df movie << Subset( Columns(), Rows(), Output Table Name( "df comedy" ), Invisible );
df family = df movie << Subset( Columns(), Rows(), Output Table Name( "df family" ), Invisible );


new win = New Window( "New Win", vlis = V List Box() );

df list = {df action, df comedy, df family};
to remove one = {"Action", "Comedy", "Family"};
to remove two = {"13", "13", "13"};
names = {"Action", "Comedy", "Family"};
ref val = {1999, 2000, 1995};
ref line = {"1999", "2000", "1995"};

For( i = 1, i <= 3, i++,
	Eval(
		Substitute(
				Expr(
					Column( _df list_, "Rating" ) << Set Property( "Value Colors", {"R" = 0} );
					_df list_ << Select Where(
						Or( !Contains( :"Type", _to remove one_ ), Contains( :"Rating", _to remove two_ ) )
					) << Exclude;
					_df list_ << Delete Rows;
				),
			Expr( _df list_ ), df list[i],
			Expr( _to remove one_ ), to remove one[i],
			Expr( _to remove two_ ), to remove two[i],

		)
	);
	If( color_or_not == 1,
		Eval(
			Substitute(
					Expr(
						graph = V List Box(
							vc = _df list_ << Variability Chart(
								Y( :Year ),
								X( :Movie ),
								Show Range Bars( 0 ),
								Show Cell Means( 0 ),
								Std Dev Chart( 0 ),
								Points Jittered( 1 ),
								Title( "Variability chart for " || _names_ ),
								SendToReport(
									Dispatch( {"Variability Chart for Year"}, "2", ScaleBox,
										{Min( -50 ), Add Ref Line( 0, "Dotted", "Medium Light Gray", "", 1 ),
										Add Ref Line(
											_ref val_, "Dotted", "Medium Light Green", _ref line_, 1
										)}
									),
									Dispatch( {""}, "Variability Chart", FrameBox,
										{Row Legend(
											Rating,
											Color( 1 ),
											Color Theme( "" ),
											Marker( 0 ),
											Marker Theme( "" ),
											Continuous Scale( 0 ),
											Reverse Scale( 0 ),
											Excluded Rows( 0 )
										)}
									)
								)
							)
						);
						Show( "at vlis" );
						vlis << Append( graph );
					),
				Expr( _df list_ ), df list[i],
				Expr( _names_ ), names[i],
				Expr( _ref val_ ), ref val[i],
				Expr( _ref line_ ), ref line[i]
			)
		)
	,
		Eval(
			Substitute(
					Expr(
						graph = V List Box(
							vc = _df list_ << Variability Chart(
								Y( :Year ),
								X( :Movie ),
								Show Range Bars( 0 ),
								Show Cell Means( 0 ),
								Std Dev Chart( 0 ),
								Points Jittered( 1 ),
								Title( "Variability chart for " || _names_ ),
								SendToReport(
									Dispatch( {"Variability Chart for Year"}, "2", ScaleBox,
										{Min( -50 ), Add Ref Line( 0, "Dotted", "Medium Light Gray", "", 1 ),
										Add Ref Line(
											_ref val_, "Dotted", "Medium Light Green", _ref line_, 1
										)}
									)
								)
							)
						);
						vlis << Append( graph );
					),
				Expr( _df list_ ), df list[i],
				Expr( _names_ ), names[i],
				Expr( _ref val_ ), ref val[i],
				Expr( _ref line_ ), ref line[i]
			)
		)
	);
);

Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: Empty window when trying to append variability charts through for loop

You left out the Eval() function in the Eval(Substitute(Expr))) processing

Names Default To Here( 1 );
Clear Globals();
Clear Log();

df movie = Open( "$SAMPLE_DATA\Movies.jmp" );

color_or_not = 1;

df action = df movie << Subset( Columns(), Rows(), Output Table Name( "df action" ), Invisible );
df comedy = df movie << Subset( Columns(), Rows(), Output Table Name( "df comedy" ), Invisible );
df family = df movie << Subset( Columns(), Rows(), Output Table Name( "df family" ), Invisible );


new win = New Window( "New Win", vlis = V List Box() );

df list = {df action, df comedy, df family};
to remove one = {"Action", "Comedy", "Family"};
to remove two = {"13", "13", "13"};
names = {"Action", "Comedy", "Family"};
ref val = {1999, 2000, 1995};
ref line = {"1999", "2000", "1995"};

For( i = 1, i <= 3, i++,
	Eval(
		Substitute(
				Expr(
					Column( _df list_, "Rating" ) << Set Property( "Value Colors", {"R" = 0} );
					_df list_ << Select Where(
						Or( !Contains( :"Type", _to remove one_ ), Contains( :"Rating", _to remove two_ ) )
					) << Exclude;
					_df list_ << Delete Rows;
				),
			Expr( _df list_ ), df list[i],
			Expr( _to remove one_ ), to remove one[i],
			Expr( _to remove two_ ), to remove two[i],

		)
	);
	If( color_or_not == 1,
		Eval(
			Substitute(
					Expr(
						graph = V List Box(
							vc = _df list_ << Variability Chart(
								Y( :Year ),
								X( :Movie ),
								Show Range Bars( 0 ),
								Show Cell Means( 0 ),
								Std Dev Chart( 0 ),
								Points Jittered( 1 ),
								Title( "Variability chart for " || _names_ ),
								SendToReport(
									Dispatch( {"Variability Chart for Year"}, "2", ScaleBox,
										{Min( -50 ), Add Ref Line( 0, "Dotted", "Medium Light Gray", "", 1 ),
										Add Ref Line(
											_ref val_, "Dotted", "Medium Light Green", _ref line_, 1
										)}
									),
									Dispatch( {""}, "Variability Chart", FrameBox,
										{Row Legend(
											Rating,
											Color( 1 ),
											Color Theme( "" ),
											Marker( 0 ),
											Marker Theme( "" ),
											Continuous Scale( 0 ),
											Reverse Scale( 0 ),
											Excluded Rows( 0 )
										)}
									)
								)
							)
						);
						Show( "at vlis" );
						vlis << Append( graph );
					),
				Expr( _df list_ ), df list[i],
				Expr( _names_ ), names[i],
				Expr( _ref val_ ), ref val[i],
				Expr( _ref line_ ), ref line[i]
			)
		)
	,
		Eval(
			Substitute(
					Expr(
						graph = V List Box(
							vc = _df list_ << Variability Chart(
								Y( :Year ),
								X( :Movie ),
								Show Range Bars( 0 ),
								Show Cell Means( 0 ),
								Std Dev Chart( 0 ),
								Points Jittered( 1 ),
								Title( "Variability chart for " || _names_ ),
								SendToReport(
									Dispatch( {"Variability Chart for Year"}, "2", ScaleBox,
										{Min( -50 ), Add Ref Line( 0, "Dotted", "Medium Light Gray", "", 1 ),
										Add Ref Line(
											_ref val_, "Dotted", "Medium Light Green", _ref line_, 1
										)}
									)
								)
							)
						);
						vlis << Append( graph );
					),
				Expr( _df list_ ), df list[i],
				Expr( _names_ ), names[i],
				Expr( _ref val_ ), ref val[i],
				Expr( _ref line_ ), ref line[i]
			)
		)
	);
);

Jim
neelsrejan
Level III

Re: Empty window when trying to append variability charts through for loop

Thanks Jim, not sure how I missed that but thanks for providing the updated code!