cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
EDM
EDM
Level II

Adding custom text and values to plots on different pages using a for loop

Hi,

 

I've attached a data table which aims to add a custom caption to each page of an X/Y plot graph builder report generated from the script saved within.

Page is being controlled by the :Group variable, I need a way to add custom text along with a custom summary statistic (%CV in this case) to the plot for each :Group.

For the most part the script is working (i.e. the text and the statistic are dispatched correctly to each plot), however the value dispatched are incorrect.

 

The script works by putting together a list of %CV values for each :Group, with the intent to be called upon later in the script for values to be dispatched to the relevant page / plot / framebox for a given :Group.

As the script is written currently, it appears that the 'for loop' will cycle to the last value in the list before starting to dispatch values to the plot for each :Group, so each plot gets the last value in the list, rather than the one relevant to it's :Group.

I believe this is due to the use of ' ; ' at the end of line 61, however if I use a ' , ' here the 'for loop' would error as there would be too many arguments within the for function.

 

I need a way to incremented to the 1st value in the list and then dispatch that value to the 1st frame box, and then increment to the 2nd value in the list and then dispatch that value to the 2nd frame box, and so on....

I also get a subscript range error which I think might be due to the way I'm trying to call values from the list within the 'for loop'. Either the subscript cannot be used that way within the for loop, or the values in the list are not accessible with the 'for loop' written the way it is currently.

 

I am hoping someone can help me approach solving this problem

 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Adding custom text and values to plots on different pages using a for loop

If you check the graphic scripts in graph builder, you will see that the cur_val isn't being evaluated. Also the indexing goes out of bounds due to the usage of Count_1 + 1. Not sure if the ScaleBox(i + 1) is correct in this modified version

View more...
Names Default To Here( 1 );

Summarize( unique_groups = by( :Group ), unique_CVs = by( :Measurement %CV ) );

CVs_list = As List( unique_groups[2] );

delvals = {"."};

For( i = 1, i <= N Items( delvals ), i++,
	Remove From( CVs_list, As List( Loc( CVs_list, delvals[i] ) ) )
);

gb = Graph Builder(
	Show Control Panel( 0 ),
	Legend Position( "Right" ),
	Variables(
		X( :Number ),
		Y( :Measurement ),
		Y( :Upper Limit, Position( 1 ) ),
		Y( :Lower Limit, Position( 1 ) ),
		Page( :Group ),
		Color( :Final Status )
	),
	Elements(
		Points( X, Y( 1 ), Legend( 1 ) ),
		Line( Y( 2 ), Y( 3 ), Legend( 2 ) )
	),
	Local Data Filter( Close Outline( 1 ) ),
	SendToReport(
		Dispatch(
			{},
			"400",
			ScaleBox,
			{Legend Model(
				1,
				Base( 0, 0, 0, Item ID( "Pass", 1 ) ),
				Base( 1, 0, 0, Item ID( "Fail 1", 1 ) ),
				Base( 2, 0, 0, Item ID( "Fail 2", 1 ) ),
				Base( 2, 0, 0, Item ID( "Fail 3", 1 ) ),
				Properties( 0, {Line Color( 4 )}, Item ID( "Pass", 1 ) ),
				Properties( 1, {Line Color( -128 )}, Item ID( "Fail 1", 1 ) ),
				Properties( 2, {Line Color( -6266528 )}, Item ID( "Fail 2", 1 ) ),
				Properties( 2, {Line Color( 3 )}, Item ID( "Fail 3", 1 ) )
			), Legend Model(
				2,
				Properties( 0, {Line Color( 3 ), Line Style( "Dashed" ), Line Width( 1 )}, Item ID( "Pass", 1 ) ),
				Properties( 1, {Line Color( 3 ), Line Style( "Dashed" ), Line Width( 1 )}, Item ID( "Fail 1", 1 ) ),
				Properties( 2, {Line Color( 3 ), Line Style( "Dashed" ), Line Width( 1 )}, Item ID( "Fail 2", 1 ) ),
				Properties( 2, {Line Color( 3 ), Line Style( "Dashed" ), Line Width( 1 )}, Item ID( "Fail 3", 1 ) )
			)}
		),
		Dispatch( {}, "400", LegendBox, {Legend Position( {1, [0, 1, 2], 2, [-1, -1, -1]} )} )
	)
);
Count_1 = N Items( gb << xpath( "//FrameBox" ) );

For( i = 1, i <= (Count_1), i++,
	cur_val = CVs_list[i];
	Eval(EvalExpr(
		gb << SendToReport(
			Dispatch( {}, "Graph Builder", FrameBox( i ), {Reference Line Order( 3 )} ),
			Dispatch(
				{},
				"Measurement",
				ScaleBox( i + 1 ),
				{Format( "Fixed Dec", 12, 2 ), Min( 0 ), Max( 0.36 ), Inc( 0.02 ), Minor Ticks( 0 )}),
			Dispatch( {}, "Y title", Text Edit Box( i - 1 ), {Set Text( "Measurement" )} ),
			Dispatch( {}, "Graph Builder", FrameBox( i ), Reorder Segs( {2, 3, 4, 5, 6, 8, 1, 6} ) ),
			Dispatch(
				{},
				"Graph Builder",
				FrameBox( i ),
				{Add Graphics Script(
					Text Color( "Red" );
					Text Font( "Segoe UI", 10, "Regular" );
					Text( Center Justified, {2000, 0.04}, "%CV:  " || Expr(cur_val) );
				)}
			)
		)
	));
);
(Report( gb ) << xpath( "//FrameBox" )) << Frame Size( 900, 500 );
Report( gb )[GraphBuilderTitleBox( 1 )] << Set Text( "Measurement vs. Number" );

Also I would most of the time suggest sending separate messages instead of using SendToReport. One example could be sending messages to modify axisboxes

jthi_0-1687891893149.png

 

-Jarmo

View solution in original post

2 REPLIES 2
jthi
Super User

Re: Adding custom text and values to plots on different pages using a for loop

If you check the graphic scripts in graph builder, you will see that the cur_val isn't being evaluated. Also the indexing goes out of bounds due to the usage of Count_1 + 1. Not sure if the ScaleBox(i + 1) is correct in this modified version

View more...
Names Default To Here( 1 );

Summarize( unique_groups = by( :Group ), unique_CVs = by( :Measurement %CV ) );

CVs_list = As List( unique_groups[2] );

delvals = {"."};

For( i = 1, i <= N Items( delvals ), i++,
	Remove From( CVs_list, As List( Loc( CVs_list, delvals[i] ) ) )
);

gb = Graph Builder(
	Show Control Panel( 0 ),
	Legend Position( "Right" ),
	Variables(
		X( :Number ),
		Y( :Measurement ),
		Y( :Upper Limit, Position( 1 ) ),
		Y( :Lower Limit, Position( 1 ) ),
		Page( :Group ),
		Color( :Final Status )
	),
	Elements(
		Points( X, Y( 1 ), Legend( 1 ) ),
		Line( Y( 2 ), Y( 3 ), Legend( 2 ) )
	),
	Local Data Filter( Close Outline( 1 ) ),
	SendToReport(
		Dispatch(
			{},
			"400",
			ScaleBox,
			{Legend Model(
				1,
				Base( 0, 0, 0, Item ID( "Pass", 1 ) ),
				Base( 1, 0, 0, Item ID( "Fail 1", 1 ) ),
				Base( 2, 0, 0, Item ID( "Fail 2", 1 ) ),
				Base( 2, 0, 0, Item ID( "Fail 3", 1 ) ),
				Properties( 0, {Line Color( 4 )}, Item ID( "Pass", 1 ) ),
				Properties( 1, {Line Color( -128 )}, Item ID( "Fail 1", 1 ) ),
				Properties( 2, {Line Color( -6266528 )}, Item ID( "Fail 2", 1 ) ),
				Properties( 2, {Line Color( 3 )}, Item ID( "Fail 3", 1 ) )
			), Legend Model(
				2,
				Properties( 0, {Line Color( 3 ), Line Style( "Dashed" ), Line Width( 1 )}, Item ID( "Pass", 1 ) ),
				Properties( 1, {Line Color( 3 ), Line Style( "Dashed" ), Line Width( 1 )}, Item ID( "Fail 1", 1 ) ),
				Properties( 2, {Line Color( 3 ), Line Style( "Dashed" ), Line Width( 1 )}, Item ID( "Fail 2", 1 ) ),
				Properties( 2, {Line Color( 3 ), Line Style( "Dashed" ), Line Width( 1 )}, Item ID( "Fail 3", 1 ) )
			)}
		),
		Dispatch( {}, "400", LegendBox, {Legend Position( {1, [0, 1, 2], 2, [-1, -1, -1]} )} )
	)
);
Count_1 = N Items( gb << xpath( "//FrameBox" ) );

For( i = 1, i <= (Count_1), i++,
	cur_val = CVs_list[i];
	Eval(EvalExpr(
		gb << SendToReport(
			Dispatch( {}, "Graph Builder", FrameBox( i ), {Reference Line Order( 3 )} ),
			Dispatch(
				{},
				"Measurement",
				ScaleBox( i + 1 ),
				{Format( "Fixed Dec", 12, 2 ), Min( 0 ), Max( 0.36 ), Inc( 0.02 ), Minor Ticks( 0 )}),
			Dispatch( {}, "Y title", Text Edit Box( i - 1 ), {Set Text( "Measurement" )} ),
			Dispatch( {}, "Graph Builder", FrameBox( i ), Reorder Segs( {2, 3, 4, 5, 6, 8, 1, 6} ) ),
			Dispatch(
				{},
				"Graph Builder",
				FrameBox( i ),
				{Add Graphics Script(
					Text Color( "Red" );
					Text Font( "Segoe UI", 10, "Regular" );
					Text( Center Justified, {2000, 0.04}, "%CV:  " || Expr(cur_val) );
				)}
			)
		)
	));
);
(Report( gb ) << xpath( "//FrameBox" )) << Frame Size( 900, 500 );
Report( gb )[GraphBuilderTitleBox( 1 )] << Set Text( "Measurement vs. Number" );

Also I would most of the time suggest sending separate messages instead of using SendToReport. One example could be sending messages to modify axisboxes

jthi_0-1687891893149.png

 

-Jarmo
EDM
EDM
Level II

Re: Adding custom text and values to plots on different pages using a for loop

Thanks very much Jarmo!