SPC CP and Cpk Chart in C# Windows Forms


In this article today we can see in detail about how to create a simple Statistical Process Control (SPC) Cp and CPk Chart.

An automobile manufacturing Industries Quality Check is a very important part for all manufacturing products. The Quality Check can be done using the Statistical Process Control charts. The SPC charts will be used to analyze the performance of each process. In this article today let's see how to analyze the process using Cp, Cpk, Pp and Ppk.

Cp and Cpk - >Process Capability

Currently the automobile industry is interested in automated measuring machines to ensure quality and to compete in the global industry. Cp, Cpk, Pp, Ppk (in other words Process Capability) takes a major role in ensuring quality by measuring automobile components.

measures how well the data fits within the spec limits (USL and LSL).

Cpk: measures how centered the data is between the spec limits.

Cp and Cpk formula




Pp and Ppk -> Process Performance

Pp: measures how well the data fits within the spec limits (USL and LSL).

Ppk: measures how centered the data is between the spec limits.
Pp and Ppk formula



Now let's see how I have created a SPC Cp and Cpk chart. My main purpose is to make a very simple SPC Chart that can be used by the end users.
I have created a SPC Cp and Cpk Chart as a User Control so that it can be used easily in all projects. In this article I have attached a Zip file named SHANUSPCCpandCpkChartSRC.zip. That contains the "ShanuCPCPKChart.dll". You can use this User Control in your project and pass the data as a DataTable to the User Cotnrol. In the User Control I will get the DataTable value and calculate:
  • Sum
  • Mean
  • Range
  • Cp
  • Cpk
  • Pp
  • Ppk
Bind all the results to the chart with a smiley alert image. If the data is good then display the Green smiley and if the data is Not Good (NG). Using the Mean and Range values I will plot the result as a Mean and Range chart with an Alert Image.

The user can pass the Upper Specification Limit (USL), Lower Specification Limit (LSL) Cpk Limit values to the ShanuCPCPKChart user control. Using the USL, LSL and Cpk value, the result will be calculated and display the appropriate alert in Red if the NG is for Cp, Cpk ,Pp, Ppk values. If the result is good then the Green text will be displayed to Cp, Cpk, Pp, Ppk in the chart.
 ShanuCpCpkChart User control Features:
  1. Display chart with Sum, Mean and Range values.
  2. Cp, Cpk, Pp, Ppk with an alert result text warning with Red for NG and Green for OK result.
  3. Mean (XBAR) and Range (RBAR) chart with an Alert image with Red for NG and Green for OK result.
  4. Automatic Calculate and display the Upper Control Limit (UCL), Lower Control Limit (LCL) value with both XBAR and RBAR values.
  5. Save the chart as an image (note: to save the chart image, double-click the chart or right-click and select save as Image).
  6. Real Time data Gathering and display the chart.
  7. The user can add Chart Watermark text.
The "ShanuSPCCpCPK_Demo" folder (this folder contains the Demo program that includes the ShanuCPCPKChart user control with the Random Data sample).

Note: I have used the DataTable as the data input for the User Control. From the Windows Forms form we need to pass the DataTable to the User Control to plot the Cp and Cpk Range Chart.
Code Part

I have used Visual Studio 2010. Create a Windows application and add and test our "ShanuCPCPKChart" User Control.
  1. Create a new Windows project.
  2. Open your form and then from Toolbox > right-click > choose items > browse to select your user control DLL and add.
  3. Drag the User Control to your Windows Forms form.
  4. Call the "Bindgrid" method of the user control and pass the DataTable to the User Control and check the result. 
  1. //Global variable Declaration  
  2. #region Local Vairables  
  3.         DataTable dt = new DataTable();  
  4.         private static readonly Random random = new Random();  
  5.         Double gridMinvalue = 1.2;  
  6.         Double gridMaxvalue = 2.4;  
  7.     int totalColumntoDisplay = 20;  
  8.         Double USLs = 2.27;  
  9.         Double LSLs = 1.26;  
  10.         Double CpkPpkAcceptanceValue = 1.33;  
  12.         #endregion  
Form Load event
In the Form Load event call the loadGridColumn() method. In this function I add the columns for the Data Table. I have used 20 columns for adding 20 sample data with 5 trials.
  1. //Create Datatable  Colums.  
  2.         public void loadGridColums()  
  3.         {  
  4.             dt.Columns.Add("No");  
  6. for (int jval = 1; jval <= totalColumntoDisplay; jval++)  
  7.              {  
  8.                 dt.Columns.Add(jval.ToString());  
  9.               }  
  10.         }  
Next in the Form Load event I call the loadgrid() method. In this method I generate sample random numbers for 20 columns to plot our chart.
  1. public void loadgrid()  
  2.         {  
  3.             dt.Clear();  
  4.             dt.Rows.Clear();  
  5.             for (int i = 1; i <= 5; i++)  
  6.             {  
  7. DataRow row = dt.NewRow();  
  8.                 row["NO"] = i.ToString();  
  9.                 for (int jval = 1; jval <= totalColumntoDisplay; jval++)  
  10.                 {  
  11.                     row[jval.ToString()] = RandomNumberBetween(gridMinvalue, gridMaxvalue);  
  12.                 }  
  14.                 dt.Rows.Add(row);  
  15.             }  
  16.             dataGridView1.AutoResizeColumns();  
  17.             dataGridView1.DataSource = dt;  
  18.             dataGridView1.AutoResizeColumns();  
  19.         }  

Next in the form load I have passed the USL, LSL and Cpk values and DataTable to “shanuCPCPKChart” User Control to generate XBAR and Range Chart with Cp, Cpk, Pp and Ppk results.

  1. private void Form1_Load(object sender, EventArgs e)  
  2.         {  
  3.             loadGridColums();  
  4.             loadgrid();  
  5.             USLs = Convert.ToDouble(txtusl.Text);  
  6.             LSLs = Convert.ToDouble(txtLSL.Text);  
  7.             CpkPpkAcceptanceValue = Convert.ToDouble(txtData.Text);  
  9.             shanuCPCPKChart.USL = USLs;  
  10.             shanuCPCPKChart.LSL = LSLs;  
  11.             shanuCPCPKChart.CpkPpKAcceptanceValue = CpkPpkAcceptanceValue;  
  12.             shanuCPCPKChart.Bindgrid(dt);     
  13.         }  
To display the real-time data chart result ,here I have used the timer and can bind the data using random data and pass all the results to the User Control to refresh and display the result.
  1. private void timer1_Tick(object sender, EventArgs e)  
  2.         {  
  3.             loadgrid();  
  4.             USLs = Convert.ToDouble(txtusl.Text);  
  5.             LSLs = Convert.ToDouble(txtLSL.Text);  
  6.             CpkPpkAcceptanceValue = Convert.ToDouble(txtData.Text);  
  8.             shanuCPCPKChart.USL = USLs;  
  9.             shanuCPCPKChart.LSL = LSLs;  
  10.             shanuCPCPKChart.CpkPpKAcceptanceValue = CpkPpkAcceptanceValue;  
  11.             shanuCPCPKChart.Bindgrid(dt);     
  12.         }  
Save Chart as Image


Similar Articles