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
DamionSparhawk
Level III

Select issue

I create a graph, and when I go to select a portion of it, it highlights the entire excel sheet. I remember from demo that you should be able to select a segment and have it only highlight the data directly relating to that segment. What am I doing wrong here?

 

I would also like to know if there is any way to have JMP find the peak data from multiple points on the same line and display them in the graph?

 

Thank you for your time

20 REPLIES 20
txnelson
Super User

Re: Select issue

Your lack of response to your latest question is in part due to the way you are displaying the code.  Passing the code in the form of a picture requires the community to have to type in all of your code manually if they are going to try to debug your code.  Could you please enter the code by using either the "Insert Code" or better yet, the "Insert JSL Script" icon.  If your browser does not support either of them, then pasting the code into the response will work.

Jim
DamionSparhawk
Level III

Re: Select issue

All of the text is in the previous post under the spoiler window, it just doesn't look right so I used pictures, I didn't know what the JSL button was for so I just copy/pasted.

dt = Open ();

col_list = dt << get column names(string);

remove from(col_list, 1);	// Remove time[sec] from list
cols_to_plot = {};
offset_list  = {};
offset_cols  = {};
// Define the graph builder commands in an expression for use by the OK button
graph_expr = expr(
	for (i = 1, i <= nitems(cols_to_plot), i++,
		new_name = cols_to_plot[i] || "-Chemical Cal";
		insertinto(offset_cols, new_name);
		dt << new column(new_name, Numeric, "Continuous", Format( "Best", 12 ),
			Formula( as column(dt, cols_to_plot[i]) * offset_list[i] ) );
			
	);
// Now for the graph - build a text string and then execute it
	gb_text = 
"\[gb = graph builder(
	show control panel(0),
	variables(
		X( :Name( "Time[sec]" ) ),]\";
	elements_txt = "	),
	Elements( Line( X, ";
	
	for (i = 1, i <= nitems(cols_to_plot), i++,
		if (i == 1,
		// then
			gb_text = gb_text || evalinsert("\!N\[		Y( :Name( "^offset_cols[i]^" ) ), ]\");
			,
		// else
			gb_text = gb_text || evalinsert("\!N\[		Y( :Name( "^offset_cols[i]^" ), Position( 1 ) ),]\");
		);

		elements_txt = elements_txt || evalinsert("Y ( ^i^ ), ");
	);

	elements_txt = elements_txt || "Legend( 7 ) ), Points( X, Y, Legend(8))
	
		
	,";

	gb_text = gb_text || elements_txt || ") )";
	eval(parse(gb_text));
	SendToReport(
		Dispatch(
			{},
			"400",
			ScaleBox,
			{Legend Model(
				8,
				Properties(
					0,
					{Marker Size( 0 ), Transparency( 0 )},
					Item ID( "^offset_cols[i]^", 1 )
				)
			)}
		)
	)
);
	

nw = new window("Graph Chemicals",
	panel box("Select channels to graph",
		lineup box(ncol(2), 
			text box("Column"), text box("Chemical Cal"),
			cb1 = checkbox("Ch1"), ch1_neb = number edit box(),
			cb2 = checkbox("Ch2"), ch2_neb = number edit box(),
			cb3 = checkbox("Ch3"), ch3_neb = number edit box(),
			cb4 = checkbox("Ch4"), ch4_neb = number edit box(),
			cb5 = checkbox("Ch5"), ch5_neb = number edit box(),
			cb6 = checkbox("Ch6"), ch6_neb = number edit box(),
			cb7 = checkbox("Ch7"), ch7_neb = number edit box(),
			cb8 = checkbox("Ch8"), ch8_neb = number edit box(),
			cb9 = checkbox("Ch9"), ch9_neb = number edit box(),
		),
	),
	panelbox("Actions",
		hlistbox(
			okb  = button box("OK",
				if (cb1 << get(1), 
					insertinto(cols_to_plot, col_list[8]);
					offset_value = ch1_neb << get;
					insertinto(offset_list, offset_value);
				);
				if (cb2 << get(1), 
					insertinto(cols_to_plot, col_list[9]);
					offset_value = ch2_neb << get;
					insertinto(offset_list, offset_value);
				);
				if (cb3 << get(1), 
					insertinto(cols_to_plot, col_list[10]);
					offset_value = ch3_neb << get;
					insertinto(offset_list, offset_value);
				);
				if (cb4 << get(1), 
					insertinto(cols_to_plot, col_list[11]);
					offset_value = ch4_neb << get;
					insertinto(offset_list, offset_value);
				);
				if (cb5 << get(1), 
					insertinto(cols_to_plot, col_list[12]);
					offset_value = ch5_neb << get;
					insertinto(offset_list, offset_value);
				);
				if (cb6 << get(1), 
					insertinto(cols_to_plot, col_list[13]);
					offset_value = ch6_neb << get;
					insertinto(offset_list, offset_value);
				);
				if (cb7 << get(1), 
					insertinto(cols_to_plot, col_list[14]);
					offset_value = ch7_neb << get;
					insertinto(offset_list, offset_value);
				);
				if (cb8 << get(1), 
					insertinto(cols_to_plot, col_list[15]);
					offset_value = ch8_neb << get;
					insertinto(offset_list, offset_value);
				);
				graph_expr;
				nw << close window;
			),
			canb = button box("Cancel", nw << close window;
			),
		)
	),
);

// Pre-check checkboxes if column exists
for (i = 1, i <= nitems(col_list), i++,
	if (col_list[i] == "Ch1", cb1 << set(1, 1),
		col_list[i] == "Ch2", cb2 << set(1, 1),
		col_list[i] == "Ch3", cb3 << set(1, 1),
		col_list[i] == "Ch4", cb4 << set(1, 1),
		col_list[i] == "Ch5", cb5 << set(1, 1),
		col_list[i] == "Ch6", cb6 << set(1, 1),
		col_list[i] == "Ch7", cb7 << set(1, 1),
		col_list[i] == "Ch8", cb8 << set(1, 1),
		col_list[i] == "Ch9", cb9 << set(1, 1),
	);
);
Graph Builder(
	Show Control Panel( 0 ),
	Variables( X( :Name( "Time[sec]" ) ), Y( :Name( "CH2-Offset" ) ) ),
	Elements( Line( X, Y, Legend( 7 ) ), Points( X, Y, Legend( 8 ) ) ),
	SendToReport(
		Dispatch(
			{},
			"400",
			ScaleBox,
			{Legend Model(
				8,
				Properties( 0, {Marker Size( 0 )}, Item ID( "CH2-Offset", 1 ) )
			)}
		)
	)
);

Graph Builder(
	Show Control Panel( 0 ),
	Variables( X( :Name( "Time[sec]" ) ), Y( :Name( "CH2-Offset" ) ) ),
	Elements( Line( X, Y, Legend( 7 ) ), Points( X, Y, Legend( 8 ) ) ),
	SendToReport(
		Dispatch(
			{},
			"400",
			ScaleBox,
			{Legend Model(
				8,
				Properties(
					0,
					{Marker Size( 0 ), Transparency( 0 )},
					Item ID( "^offset_cols[i]^", 1 )
				)
			)}
		)
	)
);
txnelson
Super User

Re: Select issue

I reworked your code a bit.

1. I added in the code to change the marker size and transparency

2. You may not have noticed the following issue, however, in the new columns you were creating, the formulas had the values of dt and i in them.  Those are memory variables that can possibly change.  (i.e. you save the table, start up a JMP session in the future, open the data table, and the columns would cause an error, because the variables dt and i are no longer available).  So I changed the code to make the formulas to have hardwired values.

Here is the code.  I made a mockup data table to test the code out, so there still maybe as issue or two.

dt = Open();

col_list = dt << get column names( string );

Remove From( col_list, 1 );	// Remove time[sec] from list
cols_to_plot = {};
offset_list = {};
offset_cols = {};

// Define the graph builder commands in an expression for use by the OK button
graph_expr = Expr(
	For( i = 1, i <= N Items( cols_to_plot ), i++,
		new_name = cols_to_plot[i] || "-Chemical Cal";
		
		// If used before, delete the column and then recreate it
		If( Try( Column( dt, new_name ) << get name, "" ) != "",
			dt << delete columns( new_name )
		);
		Insert Into( offset_cols, new_name );
		// The variable i and the column name need to be changed to their 
		// static value for the column formulas to be correct
		Eval(
			Substitute(
					Expr(
						dt << New Column( new_name,
							Numeric,
							"Continuous",
							Format( "Best", 12 ),
							Formula( __cols_to_plot__ * __offset_list__ )
						)
					),
				Expr( __cols_to_plot__ ), Parse( ":" || cols_to_plot[i] ),
				Expr( __offset_list__ ), offset_list[i]
			)
		);
			
	);
// Now for the graph - build a text string and then execute it
	gb_text = "\[gb = graph builder(
	show control panel(0),
	variables(
		X( :Name( "Time[sec]" ) ),]\";
	elements_txt = "	),
	Elements( Line( X, ";
	
	For( i = 1, i <= N Items( cols_to_plot ), i++,
		If( i == 1, 
		// then
			gb_text = gb_text || Eval Insert( "\!N\[		Y( :Name( "^offset_cols[i]^" ) ), ]\" )
		, 
		// else
			gb_text = gb_text || Eval Insert( "\!N\[		Y( :Name( "^offset_cols[i]^" ), Position( 1 ) ),]\" )
		);

		elements_txt = elements_txt || Eval Insert( "Y ( ^i^ ), " );
	);

// add in the marker and transparency code
	elements_txt = elements_txt ||
	"Legend( 7 ) ), Points( X, Y, Legend(8))),
SendToReport(
		Dispatch(
			{},
			\!"400\!",
			ScaleBox,
			{Legend Model(
				8,
				Properties( 0, {Marker Size( 0 ), Transparency( 0 )}, Item ID( \!""
	 || offset_cols[1] || "\!", 1 ) )
			)}
		)
	)";
	gb_text = gb_text || elements_txt || "); ";
	Eval( Parse( gb_text ) );
	
);
	

nw = New Window( "Graph Chemicals",
	Panel Box( "Select channels to graph",
		Lineup Box( N Col( 2 ),
			Text Box( "Column" ),
			Text Box( "Chemical Cal" ),
			cb1 = Check Box( "Ch1" ),
			ch1_neb = Number Edit Box(),
			cb2 = Check Box( "Ch2" ),
			ch2_neb = Number Edit Box(),
			cb3 = Check Box( "Ch3" ),
			ch3_neb = Number Edit Box(),
			cb4 = Check Box( "Ch4" ),
			ch4_neb = Number Edit Box(),
			cb5 = Check Box( "Ch5" ),
			ch5_neb = Number Edit Box(),
			cb6 = Check Box( "Ch6" ),
			ch6_neb = Number Edit Box(),
			cb7 = Check Box( "Ch7" ),
			ch7_neb = Number Edit Box(),
			cb8 = Check Box( "Ch8" ),
			ch8_neb = Number Edit Box(),
			cb9 = Check Box( "Ch9" ),
			ch9_neb = Number Edit Box(), 

		), 

	),
	Panel Box( "Actions",
		H List Box(
			okb = Button Box( "OK",
				If( cb1 << get( 1 ),
					Insert Into( cols_to_plot, col_list[8] );
					offset_value = ch1_neb << get;
					Insert Into( offset_list, offset_value );
				);
				If( cb2 << get( 1 ),
					Insert Into( cols_to_plot, col_list[9] );
					offset_value = ch2_neb << get;
					Insert Into( offset_list, offset_value );
				);
				If( cb3 << get( 1 ),
					Insert Into( cols_to_plot, col_list[10] );
					offset_value = ch3_neb << get;
					Insert Into( offset_list, offset_value );
				);
				If( cb4 << get( 1 ),
					Insert Into( cols_to_plot, col_list[11] );
					offset_value = ch4_neb << get;
					Insert Into( offset_list, offset_value );
				);
				If( cb5 << get( 1 ),
					Insert Into( cols_to_plot, col_list[12] );
					offset_value = ch5_neb << get;
					Insert Into( offset_list, offset_value );
				);
				If( cb6 << get( 1 ),
					Insert Into( cols_to_plot, col_list[13] );
					offset_value = ch6_neb << get;
					Insert Into( offset_list, offset_value );
				);
				If( cb7 << get( 1 ),
					Insert Into( cols_to_plot, col_list[14] );
					offset_value = ch7_neb << get;
					Insert Into( offset_list, offset_value );
				);
				If( cb8 << get( 1 ),
					Insert Into( cols_to_plot, col_list[15] );
					offset_value = ch8_neb << get;
					Insert Into( offset_list, offset_value );
				);
				graph_expr;
				nw << close window;
			),
			canb = Button Box( "Cancel", nw << close window ), 

		)
	), 

);

// Pre-check checkboxes if column exists
For( i = 1, i <= N Items( col_list ), i++,
	If(
		col_list[i] == "Ch1", cb1 << set( 1, 1 ),
		col_list[i] == "Ch2", cb2 << set( 1, 1 ),
		col_list[i] == "Ch3", cb3 << set( 1, 1 ),
		col_list[i] == "Ch4", cb4 << set( 1, 1 ),
		col_list[i] == "Ch5", cb5 << set( 1, 1 ),
		col_list[i] == "Ch6", cb6 << set( 1, 1 ),
		col_list[i] == "Ch7", cb7 << set( 1, 1 ),
		col_list[i] == "Ch8", cb8 << set( 1, 1 ),
		col_list[i] == "Ch9", cb9 << set( 1, 1 ), 

	)
);
Graph Builder(
	Show Control Panel( 0 ),
	Variables( X( :Name( "Time[sec]" ) ), Y( :Name( "CH2-Offset" ) ) ),
	Elements( Line( X, Y, Legend( 7 ) ), Points( X, Y, Legend( 8 ) ) ),
	SendToReport(
		Dispatch(
			{},
			"400",
			ScaleBox,
			{Legend Model( 8, Properties( 0, {Marker Size( 0 )}, Item ID( "CH2-Offset", 1 ) ) )}
		)
	)
);

Graph Builder(
	Show Control Panel( 0 ),
	Variables( X( :Name( "Time[sec]" ) ), Y( :Name( "CH2-Offset" ) ) ),
	Elements( Line( X, Y, Legend( 7 ) ), Points( X, Y, Legend( 8 ) ) ),
	SendToReport(
		Dispatch(
			{},
			"400",
			ScaleBox,
			{Legend Model(
				8,
				Properties( 0, {Marker Size( 0 ), Transparency( 0 )}, Item ID( "^offset_cols[i]^", 1 ) )
			)}
		)
	)
);
Jim
DamionSparhawk
Level III

Re: Select issue

huzzah! it works, it does have an error if I select a channel outside of the range I'm looking for, but that's perfectly fine because I won't be doing that far as I know.

Thank you very much!

DamionSparhawk
Level III

Re: Select issue

whoops, found a hiccup, since you changed it from a variable to a static, it only works on the first plot, and I may need to plot multiple graphs simultaneously (which is why the variable) I tried duplicating for each possible column, this works, but only if I am using the number of plots I include, and I may use less or more depending on circumstance. I cannot seem to get the variable to work for this adjustment, perhaps there is an if then argument we could provide for the additional lines so that if I'm not plotting them they won't argue with the script?

DamionSparhawk
Level III

Re: Select issue

dt = Open ();

col_list = dt << get column names(string);

remove from(col_list, 1);	// Remove time[sec] from list
cols_to_plot = {};
offset_list  = {};
offset_cols  = {};
// Define the graph builder commands in an expression for use by the OK button
graph_expr = expr(
	for (i = 1, i <= nitems(cols_to_plot), i++,
		new_name = cols_to_plot[i] || "-Chemical Cal";
		insertinto(offset_cols, new_name);
		dt << new column(new_name, Numeric, "Continuous", Format( "Best", 12 ),
			Formula( as column(dt, cols_to_plot[i]) * offset_list[i] ) );
	);
// Now for the graph - build a text string and then execute it
	gb_text = "\[gb = graph builder(
	show control panel(0),
	variables(
		X( :Name( "Time[sec]" ) ),]\";
	elements_txt = "	),
	Elements( Line( X, ";
	
	For( i = 1, i <= N Items( cols_to_plot ), i++,
		If( i == 1, 
		// then
			gb_text = gb_text || Eval Insert( "\!N\[		Y( :Name( "^offset_cols[i]^" ) ), ]\" )
		, 
		// else
			gb_text = gb_text || Eval Insert( "\!N\[		Y( :Name( "^offset_cols[i]^" ), Position( 1 ) ),]\" )
		);

		elements_txt = elements_txt || Eval Insert( "Y ( ^i^ ), " );
	);

// add in the marker and transparency code
	elements_txt = elements_txt ||
	"Legend( 7 ) ), Points( X, Y, Legend(8))),
SendToReport(
		Dispatch(
			{},
			\!"400\!",
			ScaleBox,
			{Legend Model(
				8,
				Properties( 0, {Marker Size( 0 ), Transparency( 0 )}, Item ID( \!""
	 || offset_cols[1] || "\!", 1 ), Item ID( \!""
	 || offset_cols[2] || "\!", 1 ), Item ID( \!""
	 || offset_cols[3] || "\!", 1 ) )
			)}
		)
	)";
	gb_text = gb_text || elements_txt || "); ";
	Eval( Parse( gb_text ) );
	
);


nw = new window("Graph Chemicals",
	panel box("Select channels to graph",
		lineup box(ncol(2), 
			text box("Column"), text box("Chemical Cal"),
			cb1 = checkbox("Ch1"), ch1_neb = number edit box(),
			cb2 = checkbox("Ch2"), ch2_neb = number edit box(),
			cb3 = checkbox("Ch3"), ch3_neb = number edit box(),
			cb4 = checkbox("Ch4"), ch4_neb = number edit box(),
			cb5 = checkbox("Ch5"), ch5_neb = number edit box(),
			cb6 = checkbox("Ch6"), ch6_neb = number edit box(),
			cb7 = checkbox("Ch7"), ch7_neb = number edit box(),
			cb8 = checkbox("Ch8"), ch8_neb = number edit box(),
			cb9 = checkbox("Ch9"), ch9_neb = number edit box(),
		),
	),
	panelbox("Actions",
		hlistbox(
			okb  = button box("OK",
				if (cb1 << get(1), 
					insertinto(cols_to_plot, col_list[5]);
					offset_value = ch1_neb << get;
					insertinto(offset_list, offset_value);
				);
				if (cb2 << get(1), 
					insertinto(cols_to_plot, col_list[6]);
					offset_value = ch2_neb << get;
					insertinto(offset_list, offset_value);
				);
				if (cb3 << get(1), 
					insertinto(cols_to_plot, col_list[7]);
					offset_value = ch3_neb << get;
					insertinto(offset_list, offset_value);
				);
				if (cb4 << get(1), 
					insertinto(cols_to_plot, col_list[8]);
					offset_value = ch4_neb << get;
					insertinto(offset_list, offset_value);
				);
				if (cb5 << get(1), 
					insertinto(cols_to_plot, col_list[9]);
					offset_value = ch5_neb << get;
					insertinto(offset_list, offset_value);
				);
				if (cb6 << get(1), 
					insertinto(cols_to_plot, col_list[10]);
					offset_value = ch6_neb << get;
					insertinto(offset_list, offset_value);
				);
				if (cb7 << get(1), 
					insertinto(cols_to_plot, col_list[11]);
					offset_value = ch7_neb << get;
					insertinto(offset_list, offset_value);
				);
				if (cb8 << get(1), 
					insertinto(cols_to_plot, col_list[12]);
					offset_value = ch8_neb << get;
					insertinto(offset_list, offset_value);
				);
				if (cb9 << get(1), 
					insertinto(cols_to_plot, col_list[13]);
					offset_value = ch9_neb << get;
					insertinto(offset_list, offset_value);
				);
				graph_expr;
				nw << close window;
			),
			canb = button box("Cancel", nw << close window;
			),
		)
	),
);

// Pre-check checkboxes if column exists
for (i = 1, i <= nitems(col_list), i++,
	if (col_list[i] == "Ch1", cb1 << set(1, 1),
		col_list[i] == "Ch2", cb2 << set(1, 1),
		col_list[i] == "Ch3", cb3 << set(1, 1),
		col_list[i] == "Ch4", cb4 << set(1, 1),
		col_list[i] == "Ch5", cb5 << set(1, 1),
		col_list[i] == "Ch6", cb6 << set(1, 1),
		col_list[i] == "Ch7", cb7 << set(1, 1),
		col_list[i] == "Ch8", cb8 << set(1, 1),
		col_list[i] == "Ch9", cb9 << set(1, 1),
	);
);

So this one enables me to run 3 different channels, unfortunately, I can't run -fewer- than 3 channels. I can run more than that, but any additional channels will not have the dot path included so I cannot select seperate points on the line like it is intended. If I use less than 3 channels I end up with this alert

 

JMPalert.PNG

txnelson
Super User

Re: Select issue

basically your JSL is just creating some new JSL. And when it comes to the SendToReport section, you have hardwired the code to require 3 offset_cols. This you already know, but the point I am making, is, that you are generating JSL code which you ultimately run. So what you need to do, is to break the code down, so that you check to see how many elements are in the offset_cols list, and then based upon that, only generate the JSL code for those number of elements.
Jim
DamionSparhawk
Level III

Re: Select issue

Sounds awesome, so hereby lies the rub, I dunno how to do that XD. Script is far more advanced than I am, just trying to work it into a shape to do what I need it to do, it works as is (I mean I can make it work, not it does what I need it to do) but I'd like some fit and polish, as it were. I'm digging into the literature as best I can and trying to puzzle it out but I really just don't know the lingo yet. So currently the number of channels is selected by the popup box (in the subscript) knowing that, is there a way to tell the legend how many lines I've selected in order to modify only that number of lines? Presumably this is what the variable function in the rest of the script is doing because it has no trouble with multiple lines/channels etc... Only reason I'm trying to add this part in is because with the line graph you can't select a segment to trace the correlating data. I need to be able to find the peak of a line. I would also like to have JMP put that data into the graph as well, but I assume that's going to be even more difficult than this is, since I'm asking the script to select not only different specific points in the data, but there may be more than one in a line and I need a specific one, not just the first one or the highest one. As it is I can simply use the single line for the more important data and do them one at a time, which is great progress,I could even go so far as to save multiple scripts and simply have one for each number of lines I need to plot, but I'm sure there's a better way, I just don't know how to make it happen... yet ^.^

txnelson
Super User

Re: Select issue

I am sorry, but I do not have the time to put the time into debugging and then implementing new code into a piece of code that is getting as large as your script has gotten. I wish you luck in finding someone in the community to help you.
Jim
DamionSparhawk
Level III

Re: Select issue

Fair enough, I'm not really looking for someone to put a lot of work in it, if it comes to that I'd have to call it a commision, just hoping someone might have some suggestions on what I can try or maybe point me in the right direction, I'm in the deep end with a couple of floaties and they're losing air XD