BookmarkSubscribe
Choose Language Hide Translation Bar
Thierry_S
Community Trekker

How to update multiple substitutions to add Ns to GraphBuilder script: Script included

Hi Team,

I would like to modify the script below to add Ns to the GraphBuilder via substitution of the placeholders "_text0_" to "_text5_".

I know how to implement a single substitution for the "_Yname_" placeholder but I'm running into a mental block to figure out multiple substitution.

Also, I don't know how to call a column statistic to generate dynamically the Ns for each overlay on the plots (see picture below script)

 

Names Default to Here (1);

dt = Current Data Table ();

Clist = dt << Get Column Names (String);

For (i = 932, i<= 935, i++, 
		
		gb = Expr (	Graph Builder(
						Size( 789, 440 ),
						Variables(
							X( :Visit ),
							Y( column (i) ),
							Group X( :LEAD TAG ),
							Overlay( :SHORT TAG )
						),
						Elements( Line( X, Y, Legend( 7 ), Error Bars( "Standard Error" ) ) ),
						SendToReport(
							Dispatch(
								{},
								_Yname_,
								ScaleBox,
								{Format( "Best", 12 ), Min( -1.8 ), Max( 1.0 ),
								Inc( 0.2 ), Minor Ticks( 1 ),
								Add Ref Line( 0, "Dotted", "Black", "", 2 )}
							),
							Dispatch(
								{},
								"Graph Builder",
								FrameBox,
								{Add Graphics Script(
									2,
									Description( "Script" ),
									Text( Center Justified, {0.5, -1.6}, "_text0_" )
								), Add Graphics Script(
									3,
									Description( "Script" ),
									Text( Center Justified, {0.5, -1.75}, "_text1_" )
								), Grid Line Order( 5 ), Reference Line Order( 6 )}
							),
							Dispatch(
								{},
								"Graph Builder",
								FrameBox( 2 ),
								{Left( 1 ), Right( 0 ), Top( 0 ), Bottom( 1 ),
								Add Graphics Script(
									2,
									Description( "Script" ),
									Text( Center Justified, {0.5, -1.75}, "_text3_" )
								), Add Graphics Script(
									3,
									Description( "Script" ),
									Text( Center Justified, {0.5, -1.6}, "_text2_" )
								), Grid Line Order( 5 ), Reference Line Order( 6 )}
							),
							Dispatch(
								{},
								"Graph Builder",
								FrameBox( 3 ),
								{Left( 1 ), Right( 1 ), Top( 0 ), Bottom( 1 ),
								Add Graphics Script(
									2,
									Description( "Script" ),
									Text( Center Justified, {0.5, -1.6}, "_text4_" )
								), Add Graphics Script(
									3,
									Description( "Script" ),
									Text( Center Justified, {0.5, -1.75}, "_text5_" )
								), Grid Line Order( 5 ), Reference Line Order( 6 )}
							)
						)
					)
			);	
		gbe = Eval (substitute(Name Expr (gb), Expr (_Yname_), Clist [i]));
		
		gbe << journal;
		gbe << close window;
);

GB_EXAMPLE_MASKED.png

Thierry R. Sornasse
0 Kudos
2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

Re: How to update multiple substitutions to add Ns to GraphBuilder script: Script included

Here is one way to do this.  I can not guarrentee the code will work on first try, because it is untested code, since I do not have a sample data table.  However, it should be pretty close.

Names Default to Here (1);

dt = Current Data Table ();

Clist = dt << Get Column Names (String);

For (i = 932, i<= 935, i++, 

	try( close( dtsum, nosave ) );
	dtSum = << Summary(invisible,
		Group( :LEAD TAG, :SHORT TAG ),
		N( as column( Clist[i] ) ),
		Freq( "None" ),
		Weight( "None" ),
		statistics column name format( "column" ),
		Link to original data table( 0 )
	);
		
		gb = Expr (	dt << Graph Builder(
						Size( 789, 440 ),
						Variables(
							X( :Visit ),
							Y( column (i) ),
							Group X( :LEAD TAG ),
							Overlay( :SHORT TAG )
						),
						Elements( Line( X, Y, Legend( 7 ), Error Bars( "Standard Error" ) ) ),
						SendToReport(
							Dispatch(
								{},
								_Yname_,
								ScaleBox,
								{Format( "Best", 12 ), Min( -1.8 ), Max( 1.0 ),
								Inc( 0.2 ), Minor Ticks( 1 ),
								Add Ref Line( 0, "Dotted", "Black", "", 2 )}
							),
							Dispatch(
								{},
								"Graph Builder",
								FrameBox,
								{Add Graphics Script(
									2,
									Description( "Script" ),
									Text( Center Justified, {0.5, -1.6}, _text0_ )
								), Add Graphics Script(
									3,
									Description( "Script" ),
									Text( Center Justified, {0.5, -1.75}, _text1_ )
								), Grid Line Order( 5 ), Reference Line Order( 6 )}
							),
							Dispatch(
								{},
								"Graph Builder",
								FrameBox( 2 ),
								{Left( 1 ), Right( 0 ), Top( 0 ), Bottom( 1 ),
								Add Graphics Script(
									2,
									Description( "Script" ),
									Text( Center Justified, {0.5, -1.75}, _text3_ )
								), Add Graphics Script(
									3,
									Description( "Script" ),
									Text( Center Justified, {0.5, -1.6}, _text2_ )
								), Grid Line Order( 5 ), Reference Line Order( 6 )}
							),
							Dispatch(
								{},
								"Graph Builder",
								FrameBox( 3 ),
								{Left( 1 ), Right( 1 ), Top( 0 ), Bottom( 1 ),
								Add Graphics Script(
									2,
									Description( "Script" ),
									Text( Center Justified, {0.5, -1.6}, _text4_ )
								), Add Graphics Script(
									3,
									Description( "Script" ),
									Text( Center Justified, {0.5, -1.75}, _text5_ )
								), Grid Line Order( 5 ), Reference Line Order( 6 )}
							)
						)
					)
			);	
		gbe = Eval (substitute(Name Expr (gb), Expr (_Yname_), Clist [i],
			Expr ( _text0_ ), char( column( dtSum, Clist[i] )[1] ),
			Expr ( _text1_ ), char( column( dtSum, Clist[i] )[2] ),
			Expr ( _text2_ ), char( column( dtSum, Clist[i] )[3] ),
			Expr ( _text3_ ), char( column( dtSum, Clist[i] )[4] ),
			Expr ( _text4_ ), char( column( dtSum, Clist[i] )[5] ),
			Expr ( _text5_ ), char( column( dtSum, Clist[i] )[6] )
		));
		
		gbe << journal;
		gbe << close window;
Jim
0 Kudos
Thierry_S
Community Trekker

Re: How to update multiple substitutions to add Ns to GraphBuilder script: Script included

Hi txnelson,

 

Thank you very much for your help. As you predicted, the script was 99% there I just had to add a couple of calls to the main table (dt) as shown below.

 

For (i = 932, i<= 1115, i++, 
		
		try( close( dtSum, nosave ) );
		dtSum = dt << Summary(invisible,
			Group( :LEAD TAG, :SHORT TAG ),
			N( as column( Clist[i] ) ),
			Freq( "None" ),
			Weight( "None" ),
			statistics column name format( "column" )
						
	);
		
				
		gb = Expr (	dt << Graph Builder(
							Size( 789, 440 ),
							Variables(
								X( :Visit ),
								Y( column (i) ),
								Group X( :LEAD TAG ),
								Overlay( :SHORT TAG )
							),
							Elements( Line( X, Y, Legend( 7 ), Error Bars( "Standard Error" ) ) ),
							SendToReport(
								Dispatch(
									{},
									_Yname_,
									ScaleBox,
									{Format( "Best", 12 ), Min( -1.8 ), Max( 1.0 ),
									Inc( 0.2 ), Minor Ticks( 1 ),
									Add Ref Line( 0, "Dotted", "Black", "", 2 )}
								),
								Dispatch(
									{},
									"Graph Builder",
									FrameBox,
									{Add Graphics Script(
										2,
										Description( "Script" ),
										Text( Center Justified, {0.5, -1.6}, _text0_ )
									), Add Graphics Script(
										3,
										Description( "Script" ),
										Text( Center Justified, {0.5, -1.75}, _text1_ )
									), Grid Line Order( 5 ), Reference Line Order( 6 )}
								),
								Dispatch(
									{},
									"Graph Builder",
									FrameBox( 2 ),
									{Left( 1 ), Right( 0 ), Top( 0 ), Bottom( 1 ),
									Add Graphics Script(
										2,
										Description( "Script" ),
										Text( Center Justified, {0.5, -1.75}, _text3_ )
									), Add Graphics Script(
										3,
										Description( "Script" ),
										Text( Center Justified, {0.5, -1.6}, _text2_ )
									), Grid Line Order( 5 ), Reference Line Order( 6 )}
								),
								Dispatch(
									{},
									"Graph Builder",
									FrameBox( 3 ),
									{Left( 1 ), Right( 1 ), Top( 0 ), Bottom( 1 ),
									Add Graphics Script(
										2,
										Description( "Script" ),
										Text( Center Justified, {0.5, -1.6}, _text4_ )
									), Add Graphics Script(
										3,
										Description( "Script" ),
										Text( Center Justified, {0.5, -1.75}, _text5_ )
									), Grid Line Order( 5 ), Reference Line Order( 6 )}
								)
							)
						)
			);	
		gbe = Eval (substitute(Name Expr (gb), Expr (_Yname_), Clist [i],
			Expr ( _text0_ ), char( column( dtSum, Clist[i] )[1] ),
			Expr ( _text1_ ), char( column( dtSum, Clist[i] )[2] ),
			Expr ( _text2_ ), char( column( dtSum, Clist[i] )[3] ),
			Expr ( _text3_ ), char( column( dtSum, Clist[i] )[4] ),
			Expr ( _text4_ ), char( column( dtSum, Clist[i] )[5] ),
			Expr ( _text5_ ), char( column( dtSum, Clist[i] )[6] )
		));
		
		gbe << journal;
		gbe << close window;
				
);
Thierry R. Sornasse
0 Kudos
3 REPLIES 3
txnelson
Super User

Re: How to update multiple substitutions to add Ns to GraphBuilder script: Script included

Here is one way to do this.  I can not guarrentee the code will work on first try, because it is untested code, since I do not have a sample data table.  However, it should be pretty close.

Names Default to Here (1);

dt = Current Data Table ();

Clist = dt << Get Column Names (String);

For (i = 932, i<= 935, i++, 

	try( close( dtsum, nosave ) );
	dtSum = << Summary(invisible,
		Group( :LEAD TAG, :SHORT TAG ),
		N( as column( Clist[i] ) ),
		Freq( "None" ),
		Weight( "None" ),
		statistics column name format( "column" ),
		Link to original data table( 0 )
	);
		
		gb = Expr (	dt << Graph Builder(
						Size( 789, 440 ),
						Variables(
							X( :Visit ),
							Y( column (i) ),
							Group X( :LEAD TAG ),
							Overlay( :SHORT TAG )
						),
						Elements( Line( X, Y, Legend( 7 ), Error Bars( "Standard Error" ) ) ),
						SendToReport(
							Dispatch(
								{},
								_Yname_,
								ScaleBox,
								{Format( "Best", 12 ), Min( -1.8 ), Max( 1.0 ),
								Inc( 0.2 ), Minor Ticks( 1 ),
								Add Ref Line( 0, "Dotted", "Black", "", 2 )}
							),
							Dispatch(
								{},
								"Graph Builder",
								FrameBox,
								{Add Graphics Script(
									2,
									Description( "Script" ),
									Text( Center Justified, {0.5, -1.6}, _text0_ )
								), Add Graphics Script(
									3,
									Description( "Script" ),
									Text( Center Justified, {0.5, -1.75}, _text1_ )
								), Grid Line Order( 5 ), Reference Line Order( 6 )}
							),
							Dispatch(
								{},
								"Graph Builder",
								FrameBox( 2 ),
								{Left( 1 ), Right( 0 ), Top( 0 ), Bottom( 1 ),
								Add Graphics Script(
									2,
									Description( "Script" ),
									Text( Center Justified, {0.5, -1.75}, _text3_ )
								), Add Graphics Script(
									3,
									Description( "Script" ),
									Text( Center Justified, {0.5, -1.6}, _text2_ )
								), Grid Line Order( 5 ), Reference Line Order( 6 )}
							),
							Dispatch(
								{},
								"Graph Builder",
								FrameBox( 3 ),
								{Left( 1 ), Right( 1 ), Top( 0 ), Bottom( 1 ),
								Add Graphics Script(
									2,
									Description( "Script" ),
									Text( Center Justified, {0.5, -1.6}, _text4_ )
								), Add Graphics Script(
									3,
									Description( "Script" ),
									Text( Center Justified, {0.5, -1.75}, _text5_ )
								), Grid Line Order( 5 ), Reference Line Order( 6 )}
							)
						)
					)
			);	
		gbe = Eval (substitute(Name Expr (gb), Expr (_Yname_), Clist [i],
			Expr ( _text0_ ), char( column( dtSum, Clist[i] )[1] ),
			Expr ( _text1_ ), char( column( dtSum, Clist[i] )[2] ),
			Expr ( _text2_ ), char( column( dtSum, Clist[i] )[3] ),
			Expr ( _text3_ ), char( column( dtSum, Clist[i] )[4] ),
			Expr ( _text4_ ), char( column( dtSum, Clist[i] )[5] ),
			Expr ( _text5_ ), char( column( dtSum, Clist[i] )[6] )
		));
		
		gbe << journal;
		gbe << close window;
Jim
0 Kudos
Thierry_S
Community Trekker

Re: How to update multiple substitutions to add Ns to GraphBuilder script: Script included

Hi txnelson,

 

Thank you very much for your help. As you predicted, the script was 99% there I just had to add a couple of calls to the main table (dt) as shown below.

 

For (i = 932, i<= 1115, i++, 
		
		try( close( dtSum, nosave ) );
		dtSum = dt << Summary(invisible,
			Group( :LEAD TAG, :SHORT TAG ),
			N( as column( Clist[i] ) ),
			Freq( "None" ),
			Weight( "None" ),
			statistics column name format( "column" )
						
	);
		
				
		gb = Expr (	dt << Graph Builder(
							Size( 789, 440 ),
							Variables(
								X( :Visit ),
								Y( column (i) ),
								Group X( :LEAD TAG ),
								Overlay( :SHORT TAG )
							),
							Elements( Line( X, Y, Legend( 7 ), Error Bars( "Standard Error" ) ) ),
							SendToReport(
								Dispatch(
									{},
									_Yname_,
									ScaleBox,
									{Format( "Best", 12 ), Min( -1.8 ), Max( 1.0 ),
									Inc( 0.2 ), Minor Ticks( 1 ),
									Add Ref Line( 0, "Dotted", "Black", "", 2 )}
								),
								Dispatch(
									{},
									"Graph Builder",
									FrameBox,
									{Add Graphics Script(
										2,
										Description( "Script" ),
										Text( Center Justified, {0.5, -1.6}, _text0_ )
									), Add Graphics Script(
										3,
										Description( "Script" ),
										Text( Center Justified, {0.5, -1.75}, _text1_ )
									), Grid Line Order( 5 ), Reference Line Order( 6 )}
								),
								Dispatch(
									{},
									"Graph Builder",
									FrameBox( 2 ),
									{Left( 1 ), Right( 0 ), Top( 0 ), Bottom( 1 ),
									Add Graphics Script(
										2,
										Description( "Script" ),
										Text( Center Justified, {0.5, -1.75}, _text3_ )
									), Add Graphics Script(
										3,
										Description( "Script" ),
										Text( Center Justified, {0.5, -1.6}, _text2_ )
									), Grid Line Order( 5 ), Reference Line Order( 6 )}
								),
								Dispatch(
									{},
									"Graph Builder",
									FrameBox( 3 ),
									{Left( 1 ), Right( 1 ), Top( 0 ), Bottom( 1 ),
									Add Graphics Script(
										2,
										Description( "Script" ),
										Text( Center Justified, {0.5, -1.6}, _text4_ )
									), Add Graphics Script(
										3,
										Description( "Script" ),
										Text( Center Justified, {0.5, -1.75}, _text5_ )
									), Grid Line Order( 5 ), Reference Line Order( 6 )}
								)
							)
						)
			);	
		gbe = Eval (substitute(Name Expr (gb), Expr (_Yname_), Clist [i],
			Expr ( _text0_ ), char( column( dtSum, Clist[i] )[1] ),
			Expr ( _text1_ ), char( column( dtSum, Clist[i] )[2] ),
			Expr ( _text2_ ), char( column( dtSum, Clist[i] )[3] ),
			Expr ( _text3_ ), char( column( dtSum, Clist[i] )[4] ),
			Expr ( _text4_ ), char( column( dtSum, Clist[i] )[5] ),
			Expr ( _text5_ ), char( column( dtSum, Clist[i] )[6] )
		));
		
		gbe << journal;
		gbe << close window;
				
);
Thierry R. Sornasse
0 Kudos
Highlighted

Re: How to update multiple substitutions to add Ns to GraphBuilder script: Script included

You can perform multiple substitutions with a single call of the Substitute() function.

gbe = Eval(
	Substitute( Name Expr( gb ),
		Expr( _Yname_ ), Clist[i],
		Expr( "_text0_"), "actual text",
...
	)
);
Learn it once, use it forever!