cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
csoon1
Level III

Displaying a Graph when Running a Script

Hi. I created a script for my table which I am hoping that when I right-click "Run Script" it would execute my script and display some graphs. However, when I run my main code, the graphs are automatically displayed and when I right-click "Run Script" afterwards it does nothing. I would need your help pointing out the error on my code. Thanks.

 

Below is a section of the long code.

 

aGraph = Graph Builder(
	Size( xSize, ySize ),
	Show Control Panel( 0 ),
	Variables( X( :V ), Y( :I ), Overlay( :PID ) ),
	Elements( Points( X, Y, Legend( 4 ), Jitter( 1 ) ), Line( X, Y, Legend( 6 ), Row order( 0 ), Summary Statistic( "Mean" ) ) ),
	SendToReport(
		Dispatch( {}, "ID", ScaleBox, {Scale( "Log" ), Format( "Best", 12 ), Inc( 1 ), Minor Ticks( 1 )} ),
		Dispatch( {}, "Graph Builder", FrameBox, {Marker Size( 1 ), Line Width Scale( 0.1 )} )
	)
);

bGraph = Graph Builder(
	Size( xSize, ySize ),
	Show Control Panel( 0 ),
	Variables( X( :V ), Y( :I ), Overlay( :PID ) ),
	Elements( Points( X, Y, Legend( 3 ), Jitter( 1 ) ), Line( X, Y, Legend( 5 ), Row order( 0 ), Summary Statistic( "Mean" ) ) ),
	SendToReport(
		Dispatch( {}, "IG", ScaleBox, {Scale( "Linear" ), Format( "Best", 12 ), Inc( 1 ), Minor Ticks( 1 )} ),
		Dispatch( {}, "Graph Builder", FrameBox, {Marker Size( 1 ), Line Width Scale( 0.1 )} )
	)
);
			
// Create new script
dt << New Script(
	"Plot Graph", 
				
	graphWindow = New Window( "Graphs",
		Panel Box( "Graphs",
			V List Box(
				H List Box(
					If( !Is Empty( aColumns ),
						aGraph
					), 
								
					If( !Is Empty( bColumns ),
						bGraph
					)
				)
			)
		)
	)
);
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Displaying a Graph when Running a Script

The agraph and bgraph code needs to be part of the script.  Below is a version the generates a script that will execute what you need.

Names Default To Here( 1 );
dt = Current Data Table();

// Create new script

dt << New Script(
	"Plot Graph", 
	
	aGraph = Expr(
		Graph Builder(
			Size( xSize, ySize ),
			Show Control Panel( 0 ),
			Variables( X( :V ), Y( :I ), Overlay( :PID ) ),
			Elements(
				Points( X, Y, Legend( 4 ), Jitter( 1 ) ),
				Line( X, Y, Legend( 6 ), Row order( 0 ), Summary Statistic( "Mean" ) )
			),
			SendToReport(
				Dispatch(
					{},
					"ID",
					ScaleBox,
					{Scale( "Log" ), Format( "Best", 12 ), Inc( 1 ), Minor Ticks( 1 )}
				),
				Dispatch( {}, "Graph Builder", FrameBox, {Marker Size( 1 ), Line Width Scale( 0.1 )} )
			)
		)
	);

	bGraph = Expr(
		Graph Builder(
			Size( xSize, ySize ),
			Show Control Panel( 0 ),
			Variables( X( :V ), Y( :I ), Overlay( :PID ) ),
			Elements(
				Points( X, Y, Legend( 3 ), Jitter( 1 ) ),
				Line( X, Y, Legend( 5 ), Row order( 0 ), Summary Statistic( "Mean" ) )
			),
			SendToReport(
				Dispatch(
					{},
					"IG",
					ScaleBox,
					{Scale( "Linear" ), Format( "Best", 12 ), Inc( 1 ), Minor Ticks( 1 )}
				),
				Dispatch( {}, "Graph Builder", FrameBox, {Marker Size( 1 ), Line Width Scale( 0.1 )} )
			)
		)
	);
							
	graphWindow = New Window( "Graphs",
		Panel Box( "Graphs",
			V List Box(
				H List Box(
					If( !Is Empty( aColumns ),
						aGraph
					), 
								
					If( !Is Empty( bColumns ),
						bGraph
					)
				)
			)
		)
	);
);
Jim

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: Displaying a Graph when Running a Script

The agraph and bgraph code needs to be part of the script.  Below is a version the generates a script that will execute what you need.

Names Default To Here( 1 );
dt = Current Data Table();

// Create new script

dt << New Script(
	"Plot Graph", 
	
	aGraph = Expr(
		Graph Builder(
			Size( xSize, ySize ),
			Show Control Panel( 0 ),
			Variables( X( :V ), Y( :I ), Overlay( :PID ) ),
			Elements(
				Points( X, Y, Legend( 4 ), Jitter( 1 ) ),
				Line( X, Y, Legend( 6 ), Row order( 0 ), Summary Statistic( "Mean" ) )
			),
			SendToReport(
				Dispatch(
					{},
					"ID",
					ScaleBox,
					{Scale( "Log" ), Format( "Best", 12 ), Inc( 1 ), Minor Ticks( 1 )}
				),
				Dispatch( {}, "Graph Builder", FrameBox, {Marker Size( 1 ), Line Width Scale( 0.1 )} )
			)
		)
	);

	bGraph = Expr(
		Graph Builder(
			Size( xSize, ySize ),
			Show Control Panel( 0 ),
			Variables( X( :V ), Y( :I ), Overlay( :PID ) ),
			Elements(
				Points( X, Y, Legend( 3 ), Jitter( 1 ) ),
				Line( X, Y, Legend( 5 ), Row order( 0 ), Summary Statistic( "Mean" ) )
			),
			SendToReport(
				Dispatch(
					{},
					"IG",
					ScaleBox,
					{Scale( "Linear" ), Format( "Best", 12 ), Inc( 1 ), Minor Ticks( 1 )}
				),
				Dispatch( {}, "Graph Builder", FrameBox, {Marker Size( 1 ), Line Width Scale( 0.1 )} )
			)
		)
	);
							
	graphWindow = New Window( "Graphs",
		Panel Box( "Graphs",
			V List Box(
				H List Box(
					If( !Is Empty( aColumns ),
						aGraph
					), 
								
					If( !Is Empty( bColumns ),
						bGraph
					)
				)
			)
		)
	);
);
Jim
csoon1
Level III

Re: Displaying a Graph when Running a Script

@txnelson,

 

Thanks it worked. However I have a follow-up question... the variables on my script: xSize, ySize, aColumns, and bColumns hold values outside of the new script. However when the new script is run the values are not passed inside the expression. I always have a hard time with Eval and Expr. Can you also help me point out how to fix this?

txnelson
Super User

Re: Displaying a Graph when Running a Script

The issue is one of Namespace.  Your script that has been embedded in the data table stores and gets it memory variables in a different memory location(namespace) than the script run from your script window.  However, you can create a global namespace that both scripts can use.

So if you have the code in your embedded script for setting the size pointing to the global memory space...lets say we call that space "gspace", the code in your embedded script would be

size(gspace:xSize,gspace:ySize),

and you would run in your open script window

gspace = new namespace("GSpace");
gspace:xSize = 800;
gspace:ySize = 600;

Then when you run the embedded code it will find the gSpace variables

Jim