cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Have your say in shaping JMP's future by participating in the new JMP Wish List Prioritization Survey
Choose Language Hide Translation Bar
Jackie_
Level VI

Overwrite Legends

Hi JMP Community,

 

I've a jsl script that adds a number of rows to the legends in the Graph builder, but the issue is it concatenates some garbage values, if you click on the refresh legend display option it adds "0". I do not want to add 0. Any suggestions?

 

 

Names Default To Here( 1 );

dt = Current Data Table();

New Window( "",
	modal, 
	H List Box(
		Panel Box( "Assign",
			H List Box(
				Text Box( "Enter Bin Value:" ), 				
				Spacer Box( size( 10, 0 ) ),
				ti = Text Edit Box( "", <<setwidth( 60 ) )
			), 								
			Spacer Box( size( 10, 10 ) ),
			H List Box(
				Button Box( "Assign bin", 
													
					ndies = N Items( dt << getselectedrows );													
					Caption( "Processing... please wait", Font( "Arial Black" ), spoken( 0 ) );
					Wait( 0 );														
					Try( dt << label() );														
					getbin = ti << get text();
					rowind = dt << get selected rows;
					dt << begindataupdate;
					:Bins[dt << get selected rows] = getbin;
					dt << enddataupdate;
					Caption( "Assigned", Font( "Arial Black" ), spoken( 0 ) );
					Wait( 0.2 );
					Caption( remove );
					Wait( 0 );,
					<<setIcon( "PushPin" ),
					<<Set Icon Location( "left" ),
					<<set tip( "Click to Assign a Value to dies" )
				)
			)
		),
		Button Box( "Refresh Legend",
			lgnd1 = gb << Get Legend Display;
			item1 = lgnd1 << Get Items;
			dt << Clear Selection;
			Try(
				For( i = 1, i <= N Items( item1 ), i++,
					dt << Clear Selection;

					item1[i] << set label(
						item1[i] << Get Label || "  = " || Format(
							N Items( dt << get rows where( :Bins == item1[i] << Get Label ) ),
							"Fixed Dec",
							Use thousands separator( 1 )
						)
					);
				)
			);
		
		), 
		gb = dt << Graph Builder(
			Size( 534, 456 ),
			Show Control Panel( 0 ),
			Variables( X( :X coord ), Y( :Y coord ), Color( :Bins ) ),
			Elements( Points( X, Y, Legend( 5 ) ) )
		);
		lgnd = gb << Get Legend Display;
		item = lgnd << Get Items;
		Try(
			For( i = 1, i <= N Items( item ), i++, 
				item[i] << set label(
					item[i] << Get Label || "  = " || Format(
						N Items( dt << get rows where( :Bins == item[i] << Get Label ) ),
						"Fixed Dec",
						Use thousands separator( 1 )
					) || ""
				)
			)
		);
	)
);   

 

1 REPLY 1
Craige_Hales
Super User

Re: Overwrite Legends

It probably runs this code twice

					item1[i] << set label(
						item1[i] << Get Label || "  = " || Format(
							N Items( dt << get rows where( :Bins == item1[i] << Get Label ) ),
							"Fixed Dec",
							Use thousands separator( 1 )
						)
					);

the second time through there are no matching rows because the value changed. I've not studied it to figure out the 'right' fix, but a quick and dirty fix might be to check if the value already contains "=" and don't modify it further.

Craige