Choose Language Hide Translation Bar
Highlighted
Pablo_Iglesia
Occasional Contributor

Old legends reappears when using Local Data Filter

Hello JSL Community!

 

I used a variation of code for dynamic chart legend , that works great by automatically changing the legend of a graph with only 1 click.

 

However when it tried to include the Local Data Filter into the graphs, for some reason the Border Box of the old/previous legends keep reappearing after clicking the filter. i have found a previous discussion with a basically the same issue, but unfortunate that trend from 2014 was a monologue, and when i tried all his TS steps none of them work on my case.

The legend itself is correct (the data shows the correct colors and markers), but the report window just gets super busy with all the previous border boxes.

I did got a work-around, where i just added an extra button to delete all unnecessary "legends" after the local data filter gets pressed, but they just keep re-appearing every time i hit a different filter. I was also unsuccessful at adding the code for the "delete" button inside the local data filter (so whenever i use the filter functionality it will also delete all the extra unnecessary legend boxes).

I am just wondering if there is a way to delete the "memory" stored of the previous legends in the graph. Or any work-around that can be used in this case.

 

Thanks in advance for the helps and support!!!

 

Graph before using local data filter

Graph after using local data filter

 

ssdsssssd.png

 

0 Kudos
6 REPLIES 6
Highlighted

Re: Old legends reappears when using Local Data Filter

Can you include a script that works on one of the sample JMP data tables that shows what platform you are using and how the legend is added?

Highlighted
Pablo_Iglesia
Occasional Contributor

Re: Old legends reappears when using Local Data Filter

Thank you so much for the reply. For convenience i am going to use the code from this post and I just added the Local Data Filter Section of the graph.

 

//Begin Script;
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
variables = {"age", "sex"};
// Initial nlevels is the number of levels of 'age', as it is the first by-group used.
fitVar = "age";
nlevels=6; 
 
// Creating the legend. For each selection, the previous spline fits are removed, then
// new ones are generated.
BC_legend = Panel Box( "Choose Legend", 
     legend = Radio Box(
           {"age", "sex"},
       fitVar = legend << Get Selected;

       Match( fitVar,

           "age",
			(Summarize(vals = By( :age ), c=count );
			For(ii = nlevels, ii >=1, ii--,
			obj << (Curve[1] << Remove Fit );
				);
			report(obj)[BorderBox(2)] << Delete;
			report(obj)[FrameBox(1)] << Row Legend("age", color(1), marker(1));
			obj << Group By( :age ) << Fit Spline( 0.1, standardized );
			nlevels = nItems(vals); 
				
			),

           "sex",
			(Summarize(vals = By( :sex ), c=count );
			For(ii = nlevels, ii >=1, ii--,
			obj << (Curve[1] << Remove Fit );
				);
			report(obj)[BorderBox(2)] << Delete;
			report(obj)[FrameBox(1)] << Row Legend("sex", color(1), marker(1));
			obj << Group By( :sex ) << Fit Spline( 0.1, standardized );
			nlevels = nItems(vals); )
           );
           
           ));
           
// Fitting the initial Bivariate fit with 'age' as the by-group, adding the legend
// to control the selections.           
nw = New Window( "BigClassBivariate", 
	HListBox( 
           
	obj = dt << Bivariate(
		Y( :weight ),
		X( :height ),
		Group By( :age ),
		Fit Spline( 0.1, standardized ),
		
		Local Data Filter(
		Location( {0, 0} ),
		Mode( Select( 0 ), Show( 1 ), Include( 1 ) ),
		Add Filter(
			columns( :age ),
			Display(  :age, Size( 204, 200 ), List Display )
		)
	),	
		
		SendToReport(
		Dispatch(
			{},
			"Bivar Plot",
			FrameBox,
			{Frame Size( 493, 354 ),Marker Size( 2 ), Marker Drawing Mode( "Normal" ), Row Legend(
                                                            dt:(fitVar),
                                                            Color( 1 ),
                                                            Color Theme( "JMP Default" ),
                                                            Marker( 0 ),
                                                            Marker Theme( "Standard" ),
                                                            Continuous Scale( Cont ),
                                                            Reverse Scale( 0 ),
                                                            Excluded Rows( 0 )
                                                     )}

		)
	)
		);   ,
           
    
    BC_legend
    ));      
    
//End Script;

 

0 Kudos
Highlighted
Pablo_Iglesia
Occasional Contributor

Re: Old legends reappears when using Local Data Filter

I did not realize i did not uploaded the images correctly on my original posts.

 

Graph before using local data filter

 

ssdsd.png

 

Graph after using local data filter

 

ssdsssssd.png

0 Kudos
Highlighted
Pablo_Iglesia
Occasional Contributor

Re: Old legends reappears when using Local Data Filter

So as an example with the above code. I click around a couple times between "Age" and "sex" on the choose legend section of the interface, then use the local filter and the "old" legends pop back.

today ssss.png

0 Kudos
Highlighted

Re: Old legends reappears when using Local Data Filter

First, it looks like this issue is resolved with JMP 15.  Fortunately there is an easy workaround for earlier versions.

 

When you remove the old legend using:

 

			report(obj)[BorderBox(2)] << Delete;

the display part of the legend gets removed, but the DisplayFrame still has a handle to old legend, and when you add the new legend there are now two.  You can also see this before you even touch the data filter, if you save the script for the report you will see two RowLegend() commands.  The two legends would also reappear if you use Redo Analysis on the report, with or without a data filter.

 

To ensure that the legend is completely removed and not just the display part of the legend, you can use replace the box delete with:

 

			report(obj)[OwnerBox(1)] << Remove;

This is equivalent to a right-click > Remove in the legend, which properly removes it.

 

Hope that helps!

Highlighted
Pablo_Iglesia
Occasional Contributor

Re: Old legends reappears when using Local Data Filter

That worked!!!! Fantastic thank you so much!!!! My code is beautiful now!!!

0 Kudos