cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
kachveder
Level III

"Group by" Value not Working in Graphs Based on Modal Window

Hi, 

 

(NOTE about the context: I am working on a graph template that automates making graphs for each label (A, B, C, D, and E) in the dataset (see the attached script) then to append it to the same output window for easy export and sharing. Here, I am using a single graph for label "A" as an example to prove what is wrong with my script. )

 

I have been having an issue with my JMP script not reading the selected Group-by variable from the user selection in the modal window. I want the user to select a "group by" column name from the data that could be any group-by variable and have a legend and coloring scheme as in the example below.

 

kachveder_0-1646144588345.png

 

In the attached JMP data table, my toy data has the generic "group" column. But, a user should be able to select any character variable (such as mfg site, batch, process, formulation) from the table and have the group-by legend and coloring scheme.  

 

Here is my JMP script: 

 

 

//select the data in the original data table 
Names Default To Here( 1 );
dt = Current Data Table();

/*
2/28/2022 Edit

get column names to 
1. get x-axis variable
2. get grouping variable for coloring the dots
	- needs to be a none option for when there is no group
	- logic statement later if set_groupby is "none", then no 
		- 

Also, ask user what coloring scheme should be used. 
JMP auto color (blue and red) or none (if manually coloring by, for example, batch ID)

see source: https://www.jmp.com/support/help/zh-cn/15.2/index.shtml#page/jmp/get-column-names.shtml

*/
column_names = dt << Get Column Names( Numeric, character, String  );
//TO DO: 
	//names_for_groupby_select = 
	//group by should be a character variable only, so
groupby_col_names = dt << Get Column names(character, String);

nw1 = New Window("Set X-axis and group by variable",
	<<Modal,
	Text Box ("Select the x-axis column."),
	Text Box ("i.e. time or batch"),
	xaxisselect = Radio Box(column_names), 
	Text Box ("Select the group-by column name."),
	groupby_col = Radio Box(groupby_col_names), 
	H List Box(
		Button Box("OK", 
		answers = Eval List({set_xlabel = xaxisselect << get selected, 
		set_groupby = groupby_col << get selected
		});
		nw1 << close window;
		),
		Button Box("Cancel")), 

//change popup window size
<<Size Window(300,500)

);

// If cancel or red X was clicked, stop the script
If( nw1 == {Button( -1 )}, Stop() );

groupbyvar = char(set_groupby);

/*
data
*/

//get the unique PQAs
col9 = Column(dt, "Label (y-axis)");
unique_label = Associative Array( col9 ) << get keys;

//initialize a jmp report window
nw= New Window("results",
    container = V List Box()
);

//loop through each PQA and paste results into the 
//initialized jmp report window at each iteration. 
for (i = 1, i <= N Items(unique_label), i++,
	content = V List Box(
	label_val = unique_label[i];
	dt << Select Where(:Name("Label (y-axis)") == label_val);

	//subset the selected data, but make subset data table pop-up invisible
	listDT = dt << Subset(invisible,
		output table name( "Subset where Label is " || label_val ),
		Selected rows only ( 1 ),
		Selected columns only( 1 )
	);

	//Get the measurment units formatted, if applicable
	col4 = Column( listDT, "Measurement Units");
	units = col4[1];

				// if units not null, concateninate with parentheses within the script. Else, do not concatenate. 
				// save the results of this if else statement as a string to variable called units_formatted. 
				// this should be after the units value is created in a line above.
				// NOTE: switched the conditions around for the algorithm to work.

	units_formatted = If(Is Missing(units), "", Is String(units), " (" || units || ") ");
	

	
	//number of items on the x-axis for scaling
	// i.e. number of batches or time points
	//get the unique PQAs
	colx = Column(listDT, set_xlabel); //"x axis");
	unique_xval = Associative Array( colx ) << get keys;
	//NOTE: font size subject to improvement later on or as needed
	font_size = If(N items(unique_xval) <= 9, 9, N items(unique_xval) > 9, 5);
	
	// generic chart (can be control chart or process chart)
	Oneway(
	SendToByGroup( {:Name("Label (y-axis)") == label_val}, 
			Y( :Result ),
			X( char(set_xlabel) ), //:Name("x axis") ),
			Connect Means( 1 ),
			Grand Mean( 0 ),
			SendToReport(
				Dispatch(
					{},
					"Result",
					TextEditBox,
					{Set Text( label_val || units_formatted )}
				),
				//font size:
				Dispatch(
					{},
					"2",
					ScaleBox,
					{Label Row( Set Font Size( font_size ) )}
				),
				//graph stuff: 
				Dispatch(
					{},
					"Oneway Plot",
					FrameBox,
					{Frame Size( 1000, 300 ), DispatchSeg(
						CustomStreamSeg( 6 ),
						{Line Color( "Gray" )}
					), 
					Row Legend(
					//group by this
						//:Name("Group"), //or just Group works too
						char(set_groupby), // << need to be specified by user.
						//set_groupby, // TO DO: fix this bug!
						Color( 1 ),
						Color Theme( "JMP default" ), // TO DO: << needs to be specified by user. 
						Marker( 0 ),
						Marker Theme( "" ),
						Continuous Scale( 0 ),
						Reverse Scale( 0 ),
						Excluded Rows( 0 )
					)}
				) 
				
			)
		)
	);
	);
	container << Append(content)
);

 

 

 

In this JMP script, the x-axis column selection works (see the modal window example and the resulting graph below), so I assumed that the group-by variable reference will also work as well. But the output produces a graph that does not have any group-by variable or legend. What is my code doing incorrectly here? 

 

Modal Window: 

kachveder_1-1646145386568.png

 

JMP output example graph for label "A"

 

kachveder_2-1646145510462.png

 

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
kachveder
Level III

Re: "Group by" Value not Working in Graphs Based on Modal Window

I figured the problem out via this post. 

By using Column(listDT,set_groupby) in for char(set_groupby). 

Row Legend(
					//group by this
						Column(listDT,set_groupby), 
						Color( 1 ),
						Color Theme( "JMP default" ),
						Marker( 0 ),
						Marker Theme( "" ),
						Continuous Scale( 0 ),
						Reverse Scale( 0 ),
						Excluded Rows( 0 )
					)}

View solution in original post

kachveder
Level III

Re: "Group by" Value not Working in Graphs Based on Modal Window

You can also use Eval()

Row Legend(
					//group by this
						Eval(set_groupby), 
						Color( 1 ),
						Color Theme( "JMP default" ),
						Marker( 0 ),
						Marker Theme( "" ),
						Continuous Scale( 0 ),
						Reverse Scale( 0 ),
						Excluded Rows( 0 )
					)}

View solution in original post

2 REPLIES 2
kachveder
Level III

Re: "Group by" Value not Working in Graphs Based on Modal Window

I figured the problem out via this post. 

By using Column(listDT,set_groupby) in for char(set_groupby). 

Row Legend(
					//group by this
						Column(listDT,set_groupby), 
						Color( 1 ),
						Color Theme( "JMP default" ),
						Marker( 0 ),
						Marker Theme( "" ),
						Continuous Scale( 0 ),
						Reverse Scale( 0 ),
						Excluded Rows( 0 )
					)}
kachveder
Level III

Re: "Group by" Value not Working in Graphs Based on Modal Window

You can also use Eval()

Row Legend(
					//group by this
						Eval(set_groupby), 
						Color( 1 ),
						Color Theme( "JMP default" ),
						Marker( 0 ),
						Marker Theme( "" ),
						Continuous Scale( 0 ),
						Reverse Scale( 0 ),
						Excluded Rows( 0 )
					)}