cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Discovery is online this week, April 16 and 18. Join us for these exciting interactive sessions.
Choose Language Hide Translation Bar
AT
AT
Level V

Selecting multiple columns and do histogram in a script

Hi,

I have written a script to select two columns from a table and do histogram. I like to be able to select an arbitary number of columns and do histogram for selected one. Can one help me achieve that? I have liste my script below. Thanks

dt = Open( "A.csv" );

xvar = .;

yvar = .;

win = New Window( "Choose Two Variables",

<<Modal,

<<On Validate(

// require the user to select two variables before clicking OK

Show( xvar, yvar );

If( Is Missing( xvar ) | Is Missing( yvar ),

0, // if xvar or yvar are missing, do nothing when OK is clicked

1

);

),

Text Box( " Select two numeric columns. " ),

H List Box(

Text Box( " Choose First " ),

x = Col List Box(

dt, // data table reference

all, // display all columns from the data table

xvar = (x << Get Selected)[1];

// get the name of the selected column before the window closes

Show( xvar );

),

Text Box( "Choose Second" ),

y = Col List Box(

dt,

all,

yvar = (y << Get Selected)[1];

Show( yvar );

)

)

);

 

xcol = Column( dt, xvar ); // get the columns

ycol = Column( dt, yvar );

 

name1 = ":" || xvar;

name2 = ":" || yvar;

name = name1 || "," || name2;

Show( name );

 

 

Eval(

Parse(

"obj1 = Distribution(

Stack(1),

Continuous Distribution( Column(" || name1 || ") ,

 

),

 

Continuous Distribution( Column(" || name2 ||

"),

 

)

 

);"

)

);

 

1 ACCEPTED SOLUTION

Accepted Solutions
cwillden
Super User (Alumni)

Re: Selecting multiple columns and do histogram in a script

Here's a method using colListBoxes:

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

win = New Window("Data Select",
	H List Box(
		Panel Box("Available Columns",
			dtCols = Col List Box(dt, all, width(80)),
		),
		Panel Box("Selected Columns",
			H List Box(
				V list Box(
					addButton = Button Box("Add", colList << Append(dtCols << Get Selected) ),
					removeButton = Button Box("Remove", colList << Remove Selected() )
				),
				colList = Col List Box(numeric, width(80), MinItems(1), N Lines(4))
			)
		),
		okButton = Button Box("OK",
			PlotCols = colList << Get Items;
			str = "";
			for(i=1,i<=N Items(PlotCols),i++,
				str = str||"Continuous Distribution(Column(:Name(\!""||plotcols[i]||"\!"))),
			"
			);
			eval(parse("dt << Distribution(stack(1),"||str||");"));
			win << Close Window;
		)
	)
);
-- Cameron Willden

View solution in original post

4 REPLIES 4
cwillden
Super User (Alumni)

Re: Selecting multiple columns and do histogram in a script

Here's a method using colListBoxes:

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

win = New Window("Data Select",
	H List Box(
		Panel Box("Available Columns",
			dtCols = Col List Box(dt, all, width(80)),
		),
		Panel Box("Selected Columns",
			H List Box(
				V list Box(
					addButton = Button Box("Add", colList << Append(dtCols << Get Selected) ),
					removeButton = Button Box("Remove", colList << Remove Selected() )
				),
				colList = Col List Box(numeric, width(80), MinItems(1), N Lines(4))
			)
		),
		okButton = Button Box("OK",
			PlotCols = colList << Get Items;
			str = "";
			for(i=1,i<=N Items(PlotCols),i++,
				str = str||"Continuous Distribution(Column(:Name(\!""||plotcols[i]||"\!"))),
			"
			);
			eval(parse("dt << Distribution(stack(1),"||str||");"));
			win << Close Window;
		)
	)
);
-- Cameron Willden
AT
AT
Level V

Re: Selecting multiple columns and do histogram in a script

Thanks so much for providing the solution. I tried it and it works.

AT
AT
Level V

Re: Selecting multiple columns and do histogram in a script

Hi,

Thanks again. I wanted to save the result of histogram into HTML and have done it in the past. Here is the script with some modification. I do get an error

Name Unresolved: obj in access or evaluation of 'obj'). I appreciate your help.

 

dt = Open( "A.csv" );

 

win = New Window( "Data Select",

H List Box(

Panel Box( "Available Columns", dtCols = Col List Box( dt, all, width( 80 ) ), ),

Panel Box( "Selected Columns",

H List Box(

V List Box(

addButton = Button Box( "Add", colList << Append( dtCols << Get Selected ) ),

removeButton = Button Box( "Remove", colList << Remove Selected() )

),

colList = Col List Box( numeric, width( 80 ), MinItems( 1 ), N Lines( 4 ) )

)

),

okButton = Button Box( "OK",

PlotCols = colList << Get Items;

str = "";

For( i = 1, i <= N Items( PlotCols ), i++,

str = str || "Continuous Distribution(Column(:Name(\!"" || plotcols[i] || "\!"))),

"

);

Eval( Parse( "obj = dt << Distribution(stack(1)," || str || ");" ) );

win << Close Window;

)

)

);

 

obj << report;

obj << Save Interactive HTML( "A" );

Thomas1
Level V

Re: Selecting multiple columns and do histogram in a script

Thanks. That is very helpful script.