cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
Byron_JMP
Staff
Event Lines and Comments on Control Charts

Event Lines and Comments on Control Charts

 

Annotating control charts with known events? I’m continuously running into situations where I need to add event lines to a graph. These are distinct from phases because I don’t need to recalculate the mean and control limits, I just need a marker to show that something happened. There are also cases where I need to label points on a graph in a convenient automated way. This blog covers a couple of scripts that can be added to control chart graphs that facilitate drawing event lines and adding comments to graphs.

 

Control Chart.png

The first step to customizing a graph, is to right click inside the graph and select customize, and the Customize Graph dialog appears. Clicking the “+” icon on the top left will open a blank script and this is where you can paste the examples discussed below.   This first example requires that you have a character column called “Comment” in your table. When there is a value in this column, it will cause a vertical line to be drawn on your graph like in the example above.

 

Screen Shot 2016-11-08 at 2.54.59 PM.png

 

 

The second step is to look at a couple of custom scripts that can be added to this window. Each set of instructions, or argument must be glued together with a semicolon. A good place to learn about how to use these custom scripts in graph is the Samples and Templates drop down in the dialog window. Also, the Scripting Index, under the Help tab had details on each of the functions. Keep in mind that this little script window is kind of limited, so after you apply changes, consider saving the report script to the script window to continue editing. All of the custom scripts that are added to the graph will also show up in report objects script. This dialog makes it easy to add to the graph without having to know much JSL and how to manipulate the report object’s script. 

 

 

Custom Graph Script 1:  Adding a line

For Each Row( If( Is Missing( :Comment ) == 0, V Line( row() ) ) );

Explanation:      

  • For Each Row(): this makes the formula evaluate at each row rather than at the column level.
  • Is Missing(): this function returns a “0” if the row is empty and a “1” if its not. If the row is not missing (i.e. = “0”) then the V Line gets evauated and a line is drawn.
  • V Line(): check the scripting index for this one, there a lot of interesting options to use. In this case I’m only giving it one number, so it will draw a vertical line across the entire frame at that number. (there’s no number right?)
  • Row(): this function returns the row number. I’m using this row number as the place where the vertical line is drawn through the frame.

 

Custom Graph Script 2: Adding labels to the lines

For Each Row( If( Is Missing( :Comment ) == 0, Text( Right Justified, {row(), 
Col Maximum( :Data ) * 1.2},:Comment)));

Explanation:

  • For Each Row(): this makes the formula evaluate at each row rather than at the column level.
  • If(): This is a classic “If, Then, Else” function. If the condition is true then do the first thing, or else do the second thing. Except here there is no “else”, so if the condition is true, then the first thing happens or else nothing happens.
  • Is Missing(): this function returns a “0” if the row is empty and a “1” if it’s not. Here, if the row is missing then nothing happens but if it’s not missing then the text function get evaluated.
  • Text(): Again, check the scripting index for all the arguments that can be included here, as well a couple of good examples. Here we are going to put the text at the coordinates Y and X, and the text is in the :Comment column.
  • Row() is the x-position, and y-position is the maximum (Col Maximum()) of the :Data column times 1.2. This makes the text show up a little above the data points.

 

Custom Graph Script 3: Adding labels to the data points.

It is probably better and easier to just use the column and row properties to label the data points, but in some cases a scripted solution like this is acceptably complex.

For Each Row(If( Is Missing( :Note ) == 0, If( :Data <= Col Mean( :Data ),
Text( Right Justified,{Row(),:Data-:Data*1.1}, :Note ),
Text( Right Justified,{Row(),:Data * 1.1}, :Note ))));

Explanation:

  • This gets a little fancy. In this expression there is a nested If statement. If Note is not missing and :Data is less than or equal to the column mean of :Data, then make the text in :Note be below the data point, or else make the text in :Note be above the data point.
  • It looks better in the graph this way, but in this example it starts to look a little more complicated than it needs to be.
  • A simpler version would look like this:              
For Each Row(If( Is Missing( :Note ) == 0, Text( Right Justified,{Row()+1,:Data}, :Note );

                The “row()+1” moves the text to the right of the data point

 

Example Control Chart Script

The table for this script needs to have the following columns, An example table is attached.

  •             ID, sequential row numbers
  •             Data, a column with your data to trend
  •             Comments, A sparsely populated column of comments for vertical lines
  •             Notes, A sparsely populated column of notes for specific data points

This script generates the control chart in the figure above.

Control Chart(
	Sample Label( :ID ),
	Group Size( 1 ),
	KSigma( 3 ),
	Chart Col( :Data, Individual Measurement ),
	SendToReport(
		Dispatch(
			{"Individual Measurement of Data"},
			"IR Chart of IM",
			FrameBox,
			{Frame Size( 800, 200 ), Add Graphics Script(
				1,
				Description( "Script" ),
				For Each Row( If( Is Missing( :Comment ) == 0, V Line( Row() ) ) );
				For Each Row(
					If( Is Missing( :Comment ) == 0, 
					Text( Right Justified, {Row(), Col Maximum( :Data ) * 1.2},:Comment ))
				);
				For Each Row(
					If( Is Missing( :Note ) == 0,
					If( :Data <= Col Mean( :Data ),
					Text( Right Justified,{Row(),:Data-:Data*1.1}, :Note ),
					Text( Right Justified,{Row(),:Data * 1.1}, :Note )))
				);
			), Grid Line Order( 2 ), Reference Line Order( 3 )}
		),
		Dispatch( {"Individual Measurement of Data"}, "IR Chart of IM", FrameBox( 2 ), 
{Frame Size( 72,200)})))

 

 

Last Modified: Apr 28, 2020 12:55 AM
Comments
Gadsdon
Level III

really good post thank you

Gadsdon
Level III

Hi Byron,

 

I tried to copy the script into the SPC chart builder

I have sent you a link for the file and have the following comments

1_Control Chart by ID: This is your control chart not changed - all is fine

Gadsdon_2-1586646718819.png

 

2_Control Chart by ID & Control chart builder: This is the script from (#1) copied into chart builder-the vertical lines are off set by one place on the x axis, see the 1st two special causes

 

Control Chart Builder

Gadsdon_1-1586646269320.png

3_Control Chart by ID & Control chart builder AS Numeric/Continuous: If I change the ID from Numeric/Ordinal to Numeric/Continuous then all is fine

Gadsdon_0-1586646416210.png

4_Control Chart by ID & Control chart builder AS Numeric/Continuous Alpha/numeric): But I want to plot on the x axis alpha/numeric batch number, it off sets again 

Gadsdon_1-1586646492646.png

Its driving me nuts can you help, I send you file location

https://1drv.ms/u/s!Au2FkmkZvSi-sA8j_g625J1VFdtw?e=0UPtz6

 

Cheers Ian

 

Byron_JMP
Staff

Ian,

I'm not sure what's causing that to happen (not enough coffee yet) , but this will fix it.

This is the script under the customize menu.

For Each Row( If( Is Missing( :Comment ) == 0, V Line( row()-1 ) ) );
For Each Row(
	If( Is Missing( :Comment ) == 0,
		Text( Right Justified, { row()-1, Col Maximum( :Data ) * 1.2}, :Comment )
	)
);

I substituted the :ID column for  row()-1, to use the row number for the location, and then shift it back one.

 

 

Gadsdon
Level III

Perfect, it works, so happy cheers

Gadsdon
Level III

Hi Byron, one other thing (2 actually!!), is it possible to add a tag line for the "Custom Graph Script 3: Adding labels to the data points." and is there a scripting method where you do not have to name exactly the y axis (eg ":Data"), but it defautls to the column name
Cheers Ian

Byron_JMP
Staff

1. Yes, what would you add?

2. I'm sure there is a way to do that indirectly. I think there is a way to query which columns were used to make a report, and capture the column name that way. Then append the custom script to the graph with a reference to the data column.

 

2. It would be easier if I was iterating through a list of variables and then included the reference to the current column in the custom script.