cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • Use World Cup data to build models, explore spatial relationships, and create informative visualizations in JMP. Register. July 17, 2 pm US Eastern Time.
  • Your voice matters! Tell us how you prefer to receive JMP updates, so we can tailor our communication to your needs. Take short survey.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
fkp
fkp
Level II

How can I create a column switcher in a final merged data table from a list variable created in one of the source tables?

I have two data sources that being updated on a regular basis, resulting in new columns.  These are are merged via JSL scripting which works well but, I'd like to embed a graph with a column switcher that grows as more columns are added. 

 

For example, say HPLC data comes from Instrument A and Instrument B.  Each column is a separate sample, with more samples being added over time.  I'd like to create a simple XY chart in the final data table for my 'A' samples, so that as more columns are added, the column switcher grows as well.  (Similar with B and even C, if a third instrument is added later).

 

 

fkp_0-1745489995540.png

I've created a variable from the A table before I merge the data with B, but how can I pass the list (or evaluate it ) so that the final table recognizes the variable or has explicit column names?

 

A_columns = dt_A <<Get Column Names();

//Merge A and B based on time column

Final_Table =dt_B << Update(
With(dt_A)),
Match Columns( :Time = :Time)
);
Final_Table <<New Script("Graph",
Graph Builder(
Size( 546, 565 ),
Show Control Panel( 0 ),
Variables( X( :Time ), Y( A_columns[1] ) ),
Elements( Points( X, Y, Legend( 3 ) ), Smoother( X, Y, Legend( 4 ) ) ),
Column Switcher( A_columns[1], A_columns)
);

 This seems to work well when I obtain a list of columns from the final table, but trying to use a variable created from another table is causing issues. 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How can I create a column switcher in a final merged data table from a list variable created in one of the source tables?

In that case I consider building the column list dynamically within the table script

 

Names Default To Here(1); 

dt = Open("$SAMPLE_DATA/Semiconductor Capability.jmp");

table_script_expr = Expr(
	cols = Current Data Table() << Get Column Names();
	Remove From(cols, 1); // drop first column
	gb = Graph Builder(
		Size(528, 448),
		Show Control Panel(0),
		Variables(X(:lot_id), Y(Eval(cols[1]))),
		Elements(Points(X, Y, Legend(3)))
	);
	gb << Column Switcher(
		cols[1],
		Remove(cols, 1)
	)
);

Eval(EvalExpr(
	dt << New Script("Graph",
		Expr(NameExpr(table_script_expr))
	);	
));

You can avoid evaluation if you just create the graph and save that as script (I use this "trick" quite often)

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Semiconductor Capability.jmp");

cols = dt << Get Column Names();
Remove From(cols, 1); // drop first column

gb = dt << Graph Builder(
	Size(528, 448),
	Show Control Panel(0),
	Variables(X(:lot_id), Y(Eval(cols[1]))),
	Elements(Points(X, Y, Legend(3))),
	Column Switcher(
		cols[1],
		Remove(cols, 1)
	),
	Invisible
);
gb << Save Script to Data Table("Graph"); // this will remove the need for evaluation 
wait(0);
gb << close window;

and if you wish to evaluate

// If you wish to evaluate, this should work even though the script will look a bit weird due to lack of ":" in columns
// If it doesn't you for some reason, you will have to build the list in a bit different manner for evaluation
Eval(EvalExpr(
	dt << New Script("Graph2", 
		Graph Builder(
			Size(528, 448),
			Show Control Panel(0),
			Variables(X(:lot_id), Y(Expr(cols[1]))),
			Elements(Points(X, Y, Legend(3))),
			Column Switcher(
				Expr(cols[1]),
				Expr(Remove(cols, 1))
			)
		)
	)
));

 

-Jarmo

View solution in original post

4 REPLIES 4
jthi
Super User

Re: How can I create a column switcher in a final merged data table from a list variable created in one of the source tables?

Do you always wish to use all expect for the first column (:Time) in the column switcher?

-Jarmo
fkp
fkp
Level II

Re: How can I create a column switcher in a final merged data table from a list variable created in one of the source tables?

In this case yes - always the first column which will always have the same name.

jthi
Super User

Re: How can I create a column switcher in a final merged data table from a list variable created in one of the source tables?

In that case I consider building the column list dynamically within the table script

 

Names Default To Here(1); 

dt = Open("$SAMPLE_DATA/Semiconductor Capability.jmp");

table_script_expr = Expr(
	cols = Current Data Table() << Get Column Names();
	Remove From(cols, 1); // drop first column
	gb = Graph Builder(
		Size(528, 448),
		Show Control Panel(0),
		Variables(X(:lot_id), Y(Eval(cols[1]))),
		Elements(Points(X, Y, Legend(3)))
	);
	gb << Column Switcher(
		cols[1],
		Remove(cols, 1)
	)
);

Eval(EvalExpr(
	dt << New Script("Graph",
		Expr(NameExpr(table_script_expr))
	);	
));

You can avoid evaluation if you just create the graph and save that as script (I use this "trick" quite often)

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Semiconductor Capability.jmp");

cols = dt << Get Column Names();
Remove From(cols, 1); // drop first column

gb = dt << Graph Builder(
	Size(528, 448),
	Show Control Panel(0),
	Variables(X(:lot_id), Y(Eval(cols[1]))),
	Elements(Points(X, Y, Legend(3))),
	Column Switcher(
		cols[1],
		Remove(cols, 1)
	),
	Invisible
);
gb << Save Script to Data Table("Graph"); // this will remove the need for evaluation 
wait(0);
gb << close window;

and if you wish to evaluate

// If you wish to evaluate, this should work even though the script will look a bit weird due to lack of ":" in columns
// If it doesn't you for some reason, you will have to build the list in a bit different manner for evaluation
Eval(EvalExpr(
	dt << New Script("Graph2", 
		Graph Builder(
			Size(528, 448),
			Show Control Panel(0),
			Variables(X(:lot_id), Y(Expr(cols[1]))),
			Elements(Points(X, Y, Legend(3))),
			Column Switcher(
				Expr(cols[1]),
				Expr(Remove(cols, 1))
			)
		)
	)
));

 

-Jarmo
fkp
fkp
Level II

Re: How can I create a column switcher in a final merged data table from a list variable created in one of the source tables?

Thank you!  

Recommended Articles