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
AT
AT
Level V

How to freeze control chart display when data is updated

Hi,

I have a script that read a csv file and does control chart. I like to automate this process so new data is updated, the control chart does not generate new charts. I like to only see on chart with updated data.

 

Here is the script I used. I appreciate your help. Thanks

 

------------------

Names Default To Here( 1 );

 

dt =Open(

"/Users/adatorab/Documents/JMP/PASS.csv",invisible);

 

obj = dt <<

Control Chart Builder(

Variables( Y( :A ) ),

Chart(

Position( 1 ),

Points(

Statistic(

"Individual"

)

),

Limits(

Sigma(

"Moving Range"

)

)

),

Chart(

Position( 2 ),

Points(

Statistic(

"Moving Range"

)

),

Limits(

Sigma(

"Moving Range"

)

)

)

);

obj << ShowWindow(0);

 

nw = New Window("Control Chart");

nw << Append(( H List Box( (obj << Report) << Clone Box)));

1 ACCEPTED SOLUTION

Accepted Solutions
ih
Super User (Alumni) ih
Super User (Alumni)

Re: How to freeze control chart display when data is updated

I copied Bryon's control chart code into yours, added a random 'min' time, and here is what I see:

 

control chart random start.PNG 

 

//Open a window to show a control chart and then update
//the chart every 15 seconds
//Includes a button to refresh early.
 
Names Default To Here( 1 );
 
//Define variables here that need to keep their values through subsequent function calls
//This includes the window and data table
 
//Open a window to hold the chart (note this only happens once)
nw = New Window( "Control Chart", 
	V List Box(
		Button Box( "New Data", UpdateData() ), 
		holder = H List Box();
	)
);
 
//Make a variable to hold a reference to the data table
dt = .;
 
//A function that will update the chart
UpdateData = Function( {}, 
 
	//Close the table if it is already open
	Try( dt << Close Window );
 
	//Open data table
	dt = Open( "$SAMPLE_DATA/Abrasion.jmp", Private );
 
	//Make the control chart
	obj = dt << Control Chart(
		Group Size( 1 ),
		KSigma( 3 ),
		Chart Col( :Abrasion, Individual Measurement ),
		SendToReport(
			Dispatch(
				{"Individual Measurement of Abrasion"},
				"1",
				ScaleBox,
				{Min( nrows() - Floor( Random Uniform( 10, 25 ) ) ), Max( nrows() + 2 ), Inc( 5 ),
				Minor Ticks( 1 )}
			)
		)
	);
 
 
	//Hide the temporary control chart window
	obj << ShowWindow( 0 );
 
	//Remove existing/old graph from the window (if there is one)
	Try( (holder << Child) << Delete );
 
	//Add the new graph
	holder << Append( (H List Box( (obj << Report) << Clone Box )) );
 
	//Close the temporary control chart
	obj << Close Window;
 
);
 
//Script to update then chart and then call itself 15 seconds later
quickieScript = Expr(
 
	//Load the chart in the window (run the script in the function)
	UpdateData();
 
	//Run this same script in 5 seconds
	Schedule( 5, quickieScript );
 
);
 
//Start things off:
quickieScript;

View solution in original post

12 REPLIES 12
ih
Super User (Alumni) ih
Super User (Alumni)

Re: How to freeze control chart display when data is updated

I may be going in the wrong direction here but I think you want the chart in your window to be replaced when new data shows up rather than adding another below/after it.  To do that, delete the old chart before appending a new one.  Here is an example:

 

names default to here( 1 );

//Open sample data
dt = Open("$SAMPLE_DATA/Abrasion.jmp");

//A variable used to hide part of the data
lastrow = 10;

//Hide data after the last row (simulates a smaller table)
df = dt << Data Filter(
	Location( {696, 15} ),
	Mode( Select( 0 ), Show( 1 ), Include( 1 ) ),
	Add Filter(
		columns( Transform Column( "Row", Formula( Row() ) ) ),
		Where(
			Transform Column( "Row", Formula( Row() ) ) <= lastrow
		)
	)
);

//A function that will update the chart
UpdateData = function( {},
	
	//Add one row to the data table
	lastrow++;
	
	//Update the data filter (simulates getting more data)
	df << Delete All;
	df << Add Filter(
		columns( Transform Column( "Row", Formula( Row() ) ) ),
		Where(
			Transform Column( "Row", Formula( Row() ) ) <= lastrow
		)
	);
	
	//Make the control chart
	obj = dt << Control Chart Builder(
		Variables( Y( :Abrasion ) ), 
		Chart(
			Position( 1 ), 
			Points( Statistic( "Individual" ) ), 
			Limits( Sigma( "Moving Range" ) )
		), 
		Chart(
			Position( 2 ), 
			Points( Statistic( "Moving Range" ) ), 
			Limits( Sigma( "Moving Range" ) )
		)
	);
	
	//Hide the temporary control chart window
	obj << ShowWindow(0); 

	//Remove existing/old graph from the window (if there is one)
	Try( (holder << Child) << Delete );
	
	//Add the new graph
	holder << Append(( H List Box( (obj << Report) << Clone Box)));
	
	//Close the temporary control chart
	obj << Close Window;
);

//Open a window to show the new control chart and a button to refresh the chart
//Includes a button to run the script above.
nw = New Window("Control Chart",
	V List Box(
		Button Box("New Data", UpdateData() ),
		holder = H List Box();
	)
);

//Load the first chart in the window (run the script in the function)
UpdateData();
AT
AT
Level V

Re: How to freeze control chart display when data is updated

Thanks. I use window scheduler to run this script and like to see one chart when data is read after (say 15 sec or so). I get many "control chart"). I tried your example and I put it the window task (also  Schedule function) and I get many "control chart" 1, 2, 3,.. Is there anyway you one can get only on chart?

Below is what I use. Thanks

 

//A function that will update the chart

UpdateData = function( {},

 

//Make the control chart

obj = dt << Control Chart Builder(

Variables( Y( :Abrasion ) ),

Chart(

Position( 1 ),

Points( Statistic( "Individual" ) ),

Limits( Sigma( "Moving Range" ) )

),

Chart(

Position( 2 ),

Points( Statistic( "Moving Range" ) ),

Limits( Sigma( "Moving Range" ) )

)

);

 

//Hide the temporary control chart window

obj << ShowWindow(0);

 

//Remove existing/old graph from the window (if there is one)

Try( (holder << Child) << Delete );

 

//Add the new graph

holder << Append(( H List Box( (obj << Report) << Clone Box)));

 

//Close the temporary control chart

obj << Close Window;

);

 

//Open a window to show the new control chart and a button to refresh the chart

//Includes a button to run the script above.

nw = New Window("Control Chart",

V List Box(

Button Box("New Data", UpdateData() ),

holder = H List Box();

)

);

 

//Load the first chart in the window (run the script in the function)

UpdateData();

);

quickieScript;

AT
AT
Level V

Re: How to freeze control chart display when data is updated

Sorry I  missed first few lines. Here is the correct one.

------------

names default to here( 1 );

 

 

 

quickieScript = Expr(

 

 

Schedule( 15, quickieScript );

 

 

//Open sample data

dt = Open("$SAMPLE_DATA/Abrasion.jmp");

 

//A function that will update the chart

UpdateData = function( {},

 

//Make the control chart

obj = dt << Control Chart Builder(

Variables( Y( :Abrasion ) ),

Chart(

Position( 1 ),

Points( Statistic( "Individual" ) ),

Limits( Sigma( "Moving Range" ) )

),

Chart(

Position( 2 ),

Points( Statistic( "Moving Range" ) ),

Limits( Sigma( "Moving Range" ) )

)

);

 

//Hide the temporary control chart window

obj << ShowWindow(0);

 

//Remove existing/old graph from the window (if there is one)

Try( (holder << Child) << Delete );

 

//Add the new graph

holder << Append(( H List Box( (obj << Report) << Clone Box)));

 

//Close the temporary control chart

obj << Close Window;

);

 

//Open a window to show the new control chart and a button to refresh the chart

//Includes a button to run the script above.

nw = New Window("Control Chart",

V List Box(

Button Box("New Data", UpdateData() ),

holder = H List Box();

)

);

 

//Load the first chart in the window (run the script in the function)

UpdateData();

);

quickieScript;

ih
Super User (Alumni) ih
Super User (Alumni)

Re: How to freeze control chart display when data is updated

Now I think I understand.  The problem is that you are opening a new window every time the script runs.  At the beginning of of each update you either want to close the last window or refresh the same window with a new chart.  Below is an example of the latter.

 

I often write 'pseudocode' in comments before writing any real code, I find that helps make sure code actually does what I expect it to.  Then once the whole workflow makes sense I fill in the code to actually do it.

 

//Open a window

//Every 15 Seconds:
	//Make a chart with the latest data
	//Update the window with a new chart

 

//Open a window to show a control chart and then update
//the chart every 15 seconds
//Includes a button to refresh early.

Names Default To Here( 1 );

//Define variables here that need to keep their values through subsequent function calls
//This includes the window and data table

//Open a window to hold the chart (note this only happens once)
nw = New Window( "Control Chart", 
	V List Box(
		Button Box( "New Data", UpdateData() ), 
		holder = H List Box();
	)
);

//Make a variable to hold a reference to the data table
dt = .;

//A function that will update the chart
UpdateData = Function( {}, 

	//Close the table if it is already open
	Try( dt << Close Window );
	
	//Open data table
	dt = Open( "$SAMPLE_DATA/Abrasion.jmp", Private );
	
	//Make the control chart
	obj = dt << Control Chart Builder(

		Variables( Y( :Abrasion ) ), 
		Chart(
			Position( 1 ), 
			Points( Statistic( "Individual" ) ), 
			Limits( Sigma( "Moving Range" ) )
		), 

		Chart(
			Position( 2 ), 
			Points( Statistic( "Moving Range" ) ), 
			Limits( Sigma( "Moving Range" ) )
		)
	);

	//Hide the temporary control chart window

	obj << ShowWindow( 0 );

	//Remove existing/old graph from the window (if there is one)
	Try( (holder << Child) << Delete );

	//Wait a moment to show when the chart updates
	Wait(0.2);

	//Add the new graph
	holder << Append( (H List Box( (obj << Report) << Clone Box )) );

	//Close the temporary control chart
	obj << Close Window;

);

//Script to update then chart and then call itself 15 seconds later
quickieScript = Expr(

	//Load the chart in the window (run the script in the function)
	UpdateData();
	
	//Run this same script in 15 seconds
	Schedule( 15, quickieScript );

);

//Start things off:
quickieScript;
AT
AT
Level V

Re: How to freeze control chart display when data is updated

Thank you so much. This solved my problem. 

Byron_JMP
Staff

Re: How to freeze control chart display when data is updated

Is the issue that you only want to see the most recent data in the conrol chart?

I've run into some scenerios where the data is being updated in some table. Each time I grab a copy of the table, I only want to see the last 50 rows, regardless of how many rows are in the table. 

This is pretty easy to set up.  Just make a control chart, and adjust the x axis. Then look at the control chart script and find the part that looks like the script below.

 

	SendToReport(
		Dispatch(
			{"Individual Measurement of Metric 1"},
			"1",
			ScaleBox,
			{Min( nrows()-50), Max( nrows()+2 ), Inc( 5 ),
			Minor Ticks( 0 )}
		),

Where it says Min( and Max(, edit values in the original script. Replace the number in min() with nrows()-50 and replace the number in max() with nrows()+2.  

 

Now if you do all the fancy, delete and append stuff, you'll get a control chart with the most current data.

 

JMP Systems Engineer, Health and Life Sciences (Pharma)
AT
AT
Level V

Re: How to freeze control chart display when data is updated

Thanks for your suggestions. I think that was my second question. Where do I insert your script in original script (above). 

Byron_JMP
Staff

Re: How to freeze control chart display when data is updated

This is a control chart script to run against Abrasion.jmp

Control Chart(
	Group Size( 1 ),
	KSigma( 3 ),
	Chart Col( :Abrasion, Individual Measurement ),
	SendToReport(
		Dispatch(
			{"Individual Measurement of Abrasion"},
			"1",
			ScaleBox,
			{Min( nrows()-25 ), Max( nrows()+2 ), Inc( 5 ),
			Minor Ticks( 1 )}
		)
	)
);

It uses the classic control chart platform

JMP Systems Engineer, Health and Life Sciences (Pharma)
AT
AT
Level V

Re: How to freeze control chart display when data is updated

Thanks. I tried this and I get no error but I don't see x axis only twenty points.

Can you help further? I appreciate it a lot.

//Open a window to show a control chart and then update

//the chart every 15 seconds

//Includes a button to refresh early.

 

Names Default To Here( 1 );

 

//Define variables here that need to keep their values through subsequent function calls

//This includes the window and data table

 

//Open a window to hold the chart (note this only happens once)

nw = New Window( "Control Chart",

V List Box(

Button Box( "New Data", UpdateData() ),

holder = H List Box();

)

);

 

//Make a variable to hold a reference to the data table

dt = .;

 

//A function that will update the chart

UpdateData = Function( {},

 

//Close the table if it is already open

Try( dt << Close Window );

 

//Open data table

dt = Open( "$SAMPLE_DATA/Abrasion.jmp", Private );

 

 

//Make the control chart

 

obj = dt << Control Chart Builder(

Show Two Shewhart Charts( 0 ),

Show Control Panel( 0 ),

Show Capability( 0 ),

Variables( Y( :Abrasion ) ),

Chart(

Points( Statistic( "Individual" ) ),

Limits( Sigma( Moving Range ) ),

//Warnings( Test 1( 1 ) )

SendToReport(

Dispatch(

{"Individual Measurement of Abrasion"},

"1",

ScaleBox,

{Min( nrows()-20 ), Max( nrows()+2 ), Inc( 5 ),

Minor Ticks( 1 )}

)

)

)

);

 

 

//Hide the temporary control chart window

 

obj << ShowWindow( 0 );

 

//Remove existing/old graph from the window (if there is one)

Try( (holder << Child) << Delete );

 

//Wait a moment to show when the chart updates

Wait(0.2);

 

//Add the new graph

holder << Append( (H List Box( (obj << Report) << Clone Box )) );

 

//Close the temporary control chart

obj << Close Window;

 

);

 

//Script to update then chart and then call itself 15 seconds later

quickieScript = Expr(

 

//Load the chart in the window (run the script in the function)

UpdateData();

 

//Run this same script in 15 seconds

Schedule( 15, quickieScript );

 

);

 

//Start things off:

quickieScript;