For the latest version of JMP Help, visit JMP.com/help.


Publication date: 07/24/2024

Control Chart Builder Scripts

You can use JSL to create specific control charts, customize tests, run alarm scripts, and more.

Types of Control Charts

This section describes how to create different types of control charts using JSL scripting. For a general overview of control charts, see “Control Chart Builder” in Quality and Process Methods. The basic template for scripting a chart in Control Chart Builder is as follows:

Control Chart Builder(
	Class("Shewhart Variables"|"Shewhart Attribute"|"Short Run"|"Rare Event"),
	Variables( Y( column ), <Subgroup( column )>, <Phase( column )>, <Part( column )>, <n Trials( column )>,
	<Chart(
		Position( number ),
		Points( Statistic( "statistic" ), <points options> ),
		Limits( Sigma( "sigma" ), <limits options> ),
	)>,
);

You can create different types of control charts by specifying different combinations of the Class, Variable, Statistic, and Sigma options.

The remainder of this section provides scripting templates for the different types of control charts.

Create an IMR chart by adding a continuous Y variable.

dt << Control Chart Builder( Variables( Y( continuous column ) ) );

Create an XBar/S chart by adding a Y variable and either adding a subgroup variable or defining a subgroup size. The Statistic for the dispersion chart must be set to Standard Deviation and the Sigma for the location chart must be set to Standard Deviation.

// Subgroup variable
dt << Control Chart Builder(
	Variables( Y( column ), Subgroup( column ) ),
	Chart( Position( 1 ), Limits( Sigma( "Standard Deviation" ) ) ),
	Chart( Position( 2 ),
		Points( Statistic( "Standard Deviation" ) ),
		Limits( Sigma( "Standard Deviation" ) )
	)
);
// Define subgroup size
dt << Control Chart Builder(
	Variables( Y( column ) ),
	Set Subgroup Size( number ),
	Chart( Position( 1 ), Limits( Sigma( "Standard Deviation" ) ) ),
	Chart( Position( 2 ),
		Points( Statistic( "Standard Deviation" ) ),
		Limits( Sigma( "Standard Deviation" ) )
	)
);

Create an XBar/R chart by adding a Y variable and either adding a subgroup variable or defining a subgroup size.

// Subgroup variable
dt << Control Chart Builder(
	Variables( Y( column ), Subgroup( column ) ),
);
// Define subgroup size
dt << Control Chart Builder(
	Variables( Y( column ) ),
	Set Subgroup Size ( number )
);

Create a Short Run Difference chart by setting the Class to Short Run and adding a Part variable. The Statistic values for the location chart and dispersion chart are automatically set to Centered and Moving Range Centered, respectively.

dt << Control Chart Builder(
	Class( "Short Run" ),
	Variables( Y( column ), Part( column ) )
);

Create a Short Run Standardized chart by setting the Class to Short Run and adding a Part variable. The Statistic for the location chart type must be set to Standardized and the Statistic for the dispersion chart must be set to Moving Range Standardized.

dt << Control Chart Builder(
	Class( "Short Run" ),
	Variables( Y( column ), Part( column ) ),
	Chart( Position( 1 ), Points( Statistic( "Standardized" ) ) ),
	Chart( Position( 2 ), Points( Statistic( "Moving Range Standardized" ) ) )
);

Create a Run chart by adding a Y variable, turning off the limits, and removing the dispersion chart.

dt << Control Chart Builder(
	Show Two Shewhart Charts( 0 ),
	Variables( Y( column ) ),
	Chart( Limits( Show Lower Limit( 0 ), Show Upper Limit( 0 ) ) )
);

Create a P chart by adding a Y variable, setting the Class to Shewhart Attribute, setting the Statistic to Proportion, and setting the Sigma to Binomial.

dt << Control Chart Builder(
	Class( "Shewhart Attribute" ),
	Variables( Y( column ), <Subgroup( column )>, <Phase( column )> ),
	Chart(
		Points( Statistic( "Proportion" ) ),
		Limits( Sigma( "Binomial" ) )
	)
);

Create an NP chart by adding a Y variable, setting the Class to Shewhart Attribute, setting the Statistic to Count, and setting the Sigma to Binomial.

dt << Control Chart Builder(
	Class( "Shewhart Attribute" ),
	Variables( Y( column ), <Subgroup( column )>, <Phase( column )> ),
	Chart(
		Points( Statistic( "Count" ) ),
		Limits( Sigma( "Binomial" ) )
	)
);

Create a C chart by adding a Y variable, setting the Class to Shewhart Attribute, setting the Statistic to Count, and setting the Sigma to Poisson.

dt << Control Chart Builder(
	Class( "Shewhart Attribute" ),
	Variables( Y( column ), <Subgroup( column )>, <Phase( column )> ),
	Chart(
		Points( Statistic( "Count" ) ),
		Limits( Sigma( "Poisson" ) )
	)
);

Create a U chart by adding a Y variable, setting the Class to Shewhart Attribute, setting the Statistic to Proportion, and setting the Sigma to Poisson.

dt << Control Chart Builder(
	Class( "Shewhart Attribute" ),
	Variables( Y( column ), <Subgroup( column )>, <Phase( column )> ),
	Chart(
		Points( Statistic( "Proportion" ) ),
		Limits( Sigma( "Poisson" ) )
	)
);

Create a Laney P chart by adding a Y variable, setting the Class to Shewhart Attribute, setting the Statistic to Proportion, and setting the Sigma to Laney P Prime.

dt << Control Chart Builder(
	Class( "Shewhart Attribute" ),
	Variables( Y( column ), <Subgroup( column )> ),
	Chart(
		Points( Statistic( "Proportion" ) ),
		Limits( Sigma( "Laney P Prime" ) )
	)
);

Create a Laney U chart by adding a Y variable, setting the Class to Shewhart Attribute, setting the Statistic to Proportion, and setting the Sigma to Laney U Prime.

dt << Control Chart Builder(
	Class( "Shewhart Attribute" ),
	Variables( Y( column ), <Subgroup( column )> ),
	Chart(
		Points( Statistic( "Proportion" ) ),
		Limits( Sigma( "Laney U Prime" ) )
	)
);

Create a Levey-Jennings chart by adding a Y variable, removing the dispersion chart, and setting the Sigma to Levey Jennings. The Statistic is automatically set to Individual.

dt << Control Chart Builder(
	Show Two Shewhart Charts( 0 ),
	Variables( Y( column ) ),
	Chart(
		Limits( Sigma( "Levey Jennings" ) )
	)
);

Create an IMR on Means chart by adding a Y variable and either adding a subgroup variable or defining a subgroup size. The Statistic for the dispersion chart must be set to Moving Range on Means and the Sigma on both charts must be set to Moving Range.

// Subgroup variable
dt << Control Chart Builder(
	Variables( Y( column ), Subgroup( column ) ),
	Chart( Position( 1 ), Limits( Sigma( "Moving Range" ) ) ),
	Chart( Position( 2 ),
		Points( Statistic( "Moving Range on Means" ) ),
		Limits( Sigma( "Moving Range" ) )
	)
);
// Define subgroup size
dt << Control Chart Builder(
	Variables( Y( column ) ),
	Set Subgroup Size( number ),
	Chart( Position( 1 ), Limits( Sigma( "Moving Range" ) ) ),
	Chart( Position( 2 ),
		Points( Statistic( "Moving Range on Means" ) ),
		Limits( Sigma( "Moving Range" ) )
	)
);

Create an IMR on Group Standard Deviation chart by adding a Y variable and either adding a subgroup variable or defining a subgroup size. The Statistic for the location chart must be set to Standard Deviation, the Statistic on the dispersion chart must be set to Moving Range on Std Dev, and the Sigma on both charts must be set to Moving Range.

// Subgroup variable
dt << Control Chart Builder(
	Variables( Y( column ), Subgroup( column ) ),
	Chart(
		Position( 1 ),
		Points( Statistic( "Standard Deviation" ) ),
		Limits( Sigma( "Moving Range" ) )
	),
	Chart(
		Position( 2 ),
		Points( Statistic( "Moving Range on Std Dev" ) ),
		Limits( Sigma( "Moving Range" ) )
	)
);
// Define subgroup size
dt << Control Chart Builder(
	Variables( Y( column ) ),
	Set Subgroup Size( number ),
	Chart(
		Position( 1 ),
		Points( Statistic( "Standard Deviation" ) ),
		Limits( Sigma( "Moving Range" ) )
	),
	Chart(
		Position( 2 ),
		Points( Statistic( "Moving Range on Std Dev" ) ),
		Limits( Sigma( "Moving Range" ) )
	)
);

Create a Median Moving Range chart by adding a Y variable and setting the Sigma to Median Moving Range in both the location and dispersion charts.

dt << Control Chart Builder(
	Variables( Y( column ) ),
	Chart( Position( 1 ), Limits( Sigma( "Median Moving Range" ) ) ),
	Chart( Position( 2 ), Limits( Sigma( "Median Moving Range" ) ) )
);

Create a Median Moving Range on Group Means chart by adding a Y variable and either adding a subgroup variable or defining a subgroup size. The Statistic for the dispersion chart must be set to Moving Range on Means and the Sigma on both charts must be set to Median Moving Range.

// Subgroup variable
dt << Control Chart Builder(
	Variables( Y( column ), Subgroup( column ) ),
	Chart(
		Position( 1 ),
		Limits( Sigma( "Median Moving Range" ) )
	),
	Chart(
		Position( 2 ),
		Points( Statistic( "Moving Range on Means" ) ),
		Limits( Sigma( "Median Moving Range" ) )
	)
);
// Define subgroup size
dt << Control Chart Builder(
	Variables( Y( column ) ),
	Set Subgroup Size( number ),
	Chart(
		Position( 1 ),
		Limits( Sigma( "Median Moving Range" ) )
	),
	Chart(
		Position( 2 ),
		Points( Statistic( "Moving Range on Means" ) ),
		Limits( Sigma( "Median Moving Range" ) )
	)
);

Create a Median Moving Range on Group Standard Deviations chart by adding a Y variable and either adding a subgroup variable or defining a subgroup size. The Statistic for the location chart must be set to Standard Deviation, the Statistic for the dispersion chart must be set to Moving Range on Std Dev, and the Sigma on both charts must be set to Median Moving Range.

// Subgroup variable
dt << Control Chart Builder(
	Variables( Y( column ), Subgroup( column ) ),
	Chart(
		Position( 1 ),
		Points( Statistic( "Standard Deviation" ) ),
		Limits( Sigma( "Median Moving Range" ) )
	),
	Chart(
		Position( 2 ),
		Points( Statistic( "Moving Range on Std Dev" ) ),
		Limits( Sigma( "Median Moving Range" ) )
	)
);
// Define subgroup size
dt << Control Chart Builder(
	Variables( Y( column ) ),
	Set Subgroup Size( number ),
	Chart(
		Position( 1 ),
		Points( Statistic( "Standard Deviation" ) ),
		Limits( Sigma( "Median Moving Range" ) )
	),
	Chart(
		Position( 2 ),
		Points( Statistic( "Moving Range on Std Dev" ) ),
		Limits( Sigma( "Median Moving Range" ) )
	)
);

Create a Three Way chart by adding an additional dispersion chart after adding a Y variable and adding either a Subgroup variable or defining a subgroup size.

// Subgroup variable
dt << Control Chart Builder(
	Variables( Y( column ), Subgroup( column ) ),
	Chart(
		Position( 1 ),
		Points( Statistic( "statistic" ) ),
		Limits( Sigma( "sigma" ) ),
	),
	Chart(
		Position( 2),
		Points( Statistic( "statistic" ) ),
		Limits( Sigma( "sigma" ) ),
	),
	Chart(
		Position( 3 ),
		Points( Statistic( "statistic" ) ),
		Limits( Sigma( "sigma" ) )
	)
);
// Define subgroup size
dt << Control Chart Builder(
	Variables( Y( column ) ),
	Set Subgroup Size ( number ),
	Chart(
		Position( 1 ),
		Points( Statistic( "statistic" ) ),
		Limits( Sigma( "sigma" ) ),
	),
	Chart(
		Position( 2),
		Points( Statistic( "statistic" ) ),
		Limits( Sigma( "sigma" ) ),
	),
	Chart(
		Position( 3 ),
		Points( Statistic( "statistic" ) ),
		Limits( Sigma( "sigma" ) )
	)
);

Create a G chart by setting the Class to Rare Event and adding a nonnegative discrete Y variable. The Sigma is automatically set to Negative Binomial.

dt << Control Chart Builder(
	Class( "Rare Event" ),
	Variables( Y( nonnegative discrete column ), <Subgroup( column )> ),
	Chart(
		Points( Statistic( "Count" ) )
	)
);

Create a T chart by setting the Class to Rare Event and adding a nonnegative discrete Y variable. The Sigma must be set to Weibull.

dt << Control Chart Builder(
	Class( "Rare Event" ),
	Variables( Y( nonnegative discrete column ), <Subgroup( column )> ),
	Chart(
		Points( Statistic( "Count" ) ),
		Limits( Sigma( "Weibull" ) )
	)
);

Reference Lines in Control Chart Builder

If you add a custom reference line to a Control Chart Builder chart through JSL, the reference line label must be something other than “LSL”, “USL”, or “AVG”. These names are keywords used by the Control Chart Builder platform.

The following example creates custom reference lines with unique labels.

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
obj = dt << Control Chart Builder(
	Variables( Y( :height ) ),
	SendToReport(
		Dispatch(
			{},
			"height",
			ScaleBox,
			{Add Ref Line( 70, "Solid", "Black", "Upper Limit", 1 ),
			Add Ref Line( 55, "Solid", "Black", "Lower Limit", 1 )}
		)
	)
);

Customize Tests in Control Chart Builder

You can design custom tests and select or deselect multiple tests at once using the Customize Tests function. You specify the description, desired number, and label. This option is available only for Variables and Attribute chart types.

The following example creates a custom test called Test 1 and turns it on.

dt = Open( "$SAMPLE_DATA/Quality Control/Diameter.jmp" );
dt << Control Chart Builder(
	Variables( Subgroup( :DAY ), Y( :DIAMETER ) ),
	Customize Tests( Test 1( 2, "1" ) ), // test number, n, label
	Chart( Position( 1 ), Warnings( Test 1( 1 ) ) ), // turn Test 1 on
	Chart( Position( 2 ) )
);

Run Alarm Scripts

An alarm script alerts you when the data fail one or more tests. As an Alarm Script is invoked, the following variables are available, both in the issued script and in subsequent JSL scripts:

qc_col is the name of the column

qc_test is the test that failed

qc_sample is the sample number

qc_phase is the label of the phase during which the failure occurred

qc_firstRow is the first row in the sample

qc_lastRow is the last row in the sample

Example 1: Automatically Writing to a Log

One way to generate automatic alarms is to make a script and store it with the data table as a data table script or column property named QC Alarm Script.

The following example automatically writes a message to the log whenever a test fails:

dt = Open( "$SAMPLE_DATA/Quality Control/Coating.jmp" );
obj = dt << Control Chart Builder(
	Variables( Y( :Weight ), Subgroup( :Sample ) ),
	Show Control Panel( 0 ),
	Show Limit Labels( 1 ),
		Alarm Script(
		Write(
			"Out of Control for test ",
			qc_test,
			" in column ",
			qc_col,
			" in sample ",
			qc_sample
		)
	)
);
obj << Chart( Position( 1 ), Warnings( Test 1( 1 ) ) );

Example 2: Running a Chart with Spoken Tests

You can create a control chart with tests that are spoken aloud using the Speak function. Try the following example:

dt = Open( "$SAMPLE_DATA/Quality Control/Coating.jmp" );
dt << Control Chart Builder(
	Variables( Y( :Weight ), Subgroup( :Sample ) ),
	Show Control Panel( 0 ),
	Show Limit Labels( 1 ),
	Alarm Script(
		Speak(
			Match( QC_Test,
				1, "One point beyond Zone A",
				QC_Test, 2,
				"Nine points in a row in zone C or beyond", QC_Test,
				5,
					"Two out of three points in a row in Zone A
					or beyond"
			)
		)
	),
	Chart(
		Position( 1 ),
		Warnings( Test 1( 1 ), Test 2( 1 ), Test 5( 1 ) )
	)
);

You can have either of these scripts use any of the JSL alert commands, such as Speak, Write, or Mail.

Set Phase Limits

A phase is a group of consecutive observations in the data table. For example, phases might correspond to time periods during which a new process is brought into production and then put through successive changes. Phases generate, for each level of the specified Phase variable, a new sigma, set of limits, zones, and resulting tests.

The following example illustrates setting the limits for the different phases of Diameter.jmp:

New Table( "Phase Limits",
	Add Rows( 8 ),
	New Column( "_LimitsKey", Character, Nominal,
		Set Values( {"_Sigma", "_Mean", "_LCL", "_UCL", "_Sigma", "_Mean", "_LCL", "_UCL"} )
	),
	New Column( "Phase", Character, Nominal,
		Set Values( {"1", "1", "1", "1", "2", "2", "2", "2"} )
	),
	New Column( "DIAMETER", Continuous,
		Set Values( [0.29, 4.3, 3.99, 4.72, 0.21, 4.29, 4, 4.5] )
	)
);
dt = Open( "$SAMPLE_DATA/Quality Control/Diameter.jmp" );
dt << Control Chart Builder(
	Variables( Y( :DIAMETER ), Subgroup( :DAY ), Phase( :Phase ) ),
	Show Control Panel( 0 )
);
Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).