cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP 19 is here! See the new features at jmp.com/new.
  • Register to attend Discovery Summit 2025 Online: Early Users Edition, Sept. 24-25.
Choose Language Hide Translation Bar
lodey101
Level II

Problems with Graph update function

Hi there - I have a script that works to a certain point - It gets a list of specfic columns, assigns these to a list and then uses a combobox to let the user select which column to use for a graph creation. This works fine but the problem is now that when the graph is created it will display outside the window and also appends the new graph - i just need to update the window with the new version. 

 

See the sample script below

 

 



// Create the dialog window win = New Window("Count Analysis by EXPSORTWW_XETA", V List Box( header_text, Text Box( " " ) ), VListBox( PanelBox("Controls", HListBox( TextBox("X-axis: EXP_XETA", <<Set Font Style("Bold")), Spacer Box(size(20, 1)), TextBox("Overlay Variable:"), overlayCombo = ComboBox(magicalArray, <<Set Width(200)) ) ), PanelBox("Graph", gb_test = V List Box() // Container for the graph ) ) ); // Set change handler overlayCombo << Set Function( Function({this}, overlayVar = this << Get Selected; Show( "Selected: " || overlayVar ); // Debug updateGraph( overlayVar ); ) ); updateGraph = Function({overlayVar}, // Create new graph if variable is selected write(overlayVar); gb = expr(Graph Builder( Size( 550, 450 ), Show Control Panel( 0 ), Variables( X( :EXPSORTWW_XETA ), // Explicit column reference Overlay( Column( pc_inline, overlayVar ) ) ), Elements( Bar( X, Legend(5), Summary Statistic("N"), Bar Style("Stack") ) ) )); // Add the graph to the window gb_test << Prepend( V List Box( gb )); // Optional formatting Report( gb )[FrameBox(1)] << Background Color("Light Gray") << Transparency(0.2); ); // Initialize with first variable If( N Items( magicalArray ) > 0, overlayCombo << Select( 1 ); updateGraph( magicalArray[1] ); // Force initial graph );

Could anyone help me out and see what is wrong?

 

1 REPLY 1
jthi
Super User

Re: Problems with Graph update function

This maybe gives some ideas what you could change (remove old graph, don't mix expression and reference)

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");
options = {"height", "weight"};

win = New Window("Count Analysis by EXPSORTWW_XETA",
	V List Box("", Text Box(" ")),
	V List Box(
		Panel Box("Controls",
			H List Box(
				Text Box("X-axis: EXP_XETA", <<Set Font Style("Bold")),
				Spacer Box(size(20, 1)),
				Text Box("Overlay Variable:"),
				overlayCombo = Combo Box(options, <<Set Width(200))
			)
		),
		Panel Box("Graph",
			gb_test = V List Box() 
		)
	)
);

overlayCombo << Set Function(
	Function({this},
		overlayVar = this << Get Selected;
		updateGraph(overlayVar);
	)
);

updateGraph = Function({overlayVar}, 
	gb_expr = Expr(
		gb = Graph Builder(
			Size(550, 450),
			Show Control Panel(0),
			Variables(
				X(:age), 
				Overlay(Eval(overlayVar))
			),
			Elements(Bar(X, Legend(5), Summary Statistic("N"), Bar Style("Stack")))
		)
	);
	Try((gb_test << child) << Delete Box);
	gb_test << Prepend(V List Box(gb_expr));

	Report(gb)[FrameBox(1)] << Background Color("Light Gray") << Transparency(0.2);
);

If(N Items(options) > 0,
	updateGraph(options[1]); 
);
-Jarmo

Recommended Articles