cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
AbbWorld27
Level II

How can I use the combo box to skip over certain columns for legend?

Hi,

 

I am trying to only display certain columns in the combo box as legends, but the current code I have takes the column one by one. Is there any way in which I can skip over certain columns?

For example, in this case, I only want :subject & :season in the legend list. Here's my code:

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA/Animals.jmp", invisible );
legend_list = {"subject", "season"};

gb_default = Expr(
	Graph Builder(
		Size( 544, 356 ),
		Show Control Panel( 0 ),
		Legend Position( "Bottom" ),
		Fit to Window( "Off" ),
		Variables( X( :species ), Y( :miles ), Color( :subject ) ),
		Elements( Points( X, Y, Legend( 14 ) ) ),
		SendToReport( Dispatch( {}, "400", LegendBox, {Orientation( "Horizontal" ), Sides( "Left" )} ) )
	)
);


gb_change = Expr(
	Graph Builder(
		Size( 544, 356 ),
		Show Control Panel( 0 ),
		Legend Position( "Bottom" ),
		Fit to Window( "Off" ),
		Variables( X( :species ), Y( :miles ), Color( Column( dt, ycol ) ) ),
		Elements( Points( X, Y, Legend( 14 ) ) ),
		SendToReport( Dispatch( {}, "400", LegendBox, {Orientation( "Horizontal" ), Sides( "Left" )} ) )
	)
);

nw = New Window( "Animals Monitoring ",
	gb = gb_default;
	lbcontent = Lineup Box( N Col( 10 ),
		Spacer Box( Size( 1, 0 ) ),
		Text Box( "Color: ", <<Set Font Size( 10 ) ),
		ycb = Combo Box(
			legend_list,
			<<Set( 1 ),
			<<Set Function(
				Function( {},
					ycol = ycb << Get;
					gb << delete;
					nw << Prepend( gb = gb_change );
				)
			)
		)
	);
);



Thanks for your help in advance.

dk
1 ACCEPTED SOLUTION

Accepted Solutions
pauldeen
Level VI

Re: How can I use the combo box to skip over certain columns for legend?

Two column switchers look pretty good to me:

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA/Animals.jmp", invisible);;
legend_list = {"subject","season"};
Graph Builder(
	Size( 544, 356 ),
	Show Control Panel( 0 ),
	Legend Position( "Bottom" ),
	Fit to Window( "Off" ),
	Variables( X( :species ), Y( :miles ), Color( :subject ) ),
	Elements( Points( X, Y, Legend( 14 ) ) ),
	Column Switcher( :subject, legend_list, Title( "Column Switcher Legend" ) ),
	Column Switcher( :species, {:species, :season}, Title( "Column Switcher X" ) )
);

In this examples some clashes occur as they are using the same variable Season but that is handled gracefully with an error message and will probably not happen in your real dataset.

pauldeen_0-1668693063674.png

 

View solution in original post

5 REPLIES 5
pauldeen
Level VI

Re: How can I use the combo box to skip over certain columns for legend?

You missed a ) at the end of your example script. Please also use the <JSL> tag in the insert menu to paste code. This is what it should look like:

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA/Animals.jmp", invisible);;
legend_list = {"subject","season"};

gb_default = Expr(
	Graph Builder(
		Size( 544, 356 ),
		Show Control Panel( 0 ),
		Legend Position( "Bottom" ),
		Fit to Window( "Off" ),
		Variables( X( :species ), Y( :miles ), Color( :subject ) ),
		Elements( Points( X, Y, Legend( 14 ) ) ),
		SendToReport( Dispatch( {}, "400", LegendBox, {Orientation( "Horizontal" ), Sides( "Left" )} ) )
	)
);


gb_change = Expr(
	Graph Builder(
		Size( 544, 356 ),
		Show Control Panel( 0 ),
		Legend Position( "Bottom" ),
		Fit to Window( "Off" ),
		Variables( X( :species ), Y( :miles ), Color( Column( dt, ycol ) ) ),
		Elements( Points( X, Y, Legend( 14 ) ) ),
		SendToReport( Dispatch( {}, "400", LegendBox, {Orientation( "Horizontal" ), Sides( "Left" )} ) )
	)
);

nw = New Window( "Animals Monitoring ",
	gb = gb_default;
	lbcontent = Lineup Box( N Col( 10 ),
		Spacer Box( Size( 1, 0 ) ),
		Text Box( "Color: ", <<Set Font Size( 10 ) ),
		ycb = Combo Box(
			legend_list,
			<<Set( 1 ),
			<<Set Function(
				Function( {},
					ycol = ycb << Get;
					gb << delete;
					nw << Prepend( gb = gb_change );
				)
			)
		)
	);
);

As far as I can tell, you code works...so what is your question exactly?

 

pauldeen_0-1668434166939.png

 

AbbWorld27
Level II

Re: How can I use the combo box to skip over certain columns for legend?

Hi Pauldeen, Thanks for your input.

 

My code is working, but if you click on season in the combo box, it doesn't change the legend.

 

The two combo options I have right now - 

Click Species - It shows species as legend

Click Season - It shows subject as legend

 

whereas I want if you click species - it show species as legend and same for season. Hope that clarifies. Thanks!

test.PNG

 

dk
pauldeen
Level VI

Re: How can I use the combo box to skip over certain columns for legend?

How about using the column switcher?

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA/Animals.jmp", invisible);;
legend_list = {"subject","season"};
Graph Builder(
	Size( 544, 356 ),
	Show Control Panel( 0 ),
	Legend Position( "Bottom" ),
	Fit to Window( "Off" ),
	Variables( X( :species ), Y( :miles ), Color( :subject ) ),
	Elements( Points( X, Y, Legend( 14 ) ) ),
	Column Switcher( :subject, legend_list )
);
AbbWorld27
Level II

Re: How can I use the combo box to skip over certain columns for legend?

Should have mentioned that I did try using the column switcher, but I also will be including another combo box in the tool

One combo box - for changing x-axis

One combo box - for changing legend/color

 

The column switcher isn't doing a good job at that, as it keeps on repeating for me.

desktop.PNG

dk
pauldeen
Level VI

Re: How can I use the combo box to skip over certain columns for legend?

Two column switchers look pretty good to me:

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA/Animals.jmp", invisible);;
legend_list = {"subject","season"};
Graph Builder(
	Size( 544, 356 ),
	Show Control Panel( 0 ),
	Legend Position( "Bottom" ),
	Fit to Window( "Off" ),
	Variables( X( :species ), Y( :miles ), Color( :subject ) ),
	Elements( Points( X, Y, Legend( 14 ) ) ),
	Column Switcher( :subject, legend_list, Title( "Column Switcher Legend" ) ),
	Column Switcher( :species, {:species, :season}, Title( "Column Switcher X" ) )
);

In this examples some clashes occur as they are using the same variable Season but that is handled gracefully with an error message and will probably not happen in your real dataset.

pauldeen_0-1668693063674.png