Click here to Skip to main content
15,885,216 members
Articles / Multimedia / GDI+

Control Chart Using .NET

Rate me:
Please Sign up or sign in to vote.
4.66/5 (22 votes)
27 Jan 2015CPOL4 min read 46.6K   2.1K   36   6
USL/LSL Control Chart using .NET for Quality Control

Image 1

Introduction

Nowadays, automobile industry is interested in automated measuring machines to ensure quality and to compete in the global industry. Control Chart takes a major role in ensuring quality by measuring automobile components. The purpose is to make a simple Control Bar Chart for Measuring Systems like Camshaft, Crankshaft, and Master Setting, and so on. A digital sensor is used for measuring Camshaft and Crankshaft. Then the measured data is analyzed using the Control Chart .

Control Chart(ref)

The Control Charts are graphs which is used to check the quality of control of a process. In Control charts, UCL/LCL or USL/LSL will be used to check with the resultant data. If Measurement data is within the range of limits, then the process is OK(GOOD). If the Measurement data is above or below the limits, the process is NG(NOT GOOD).

  1. OK (GOOD) -> USL <= Measurement Data >= LSL
  2. NG (NOT GOOD) -> Upper Range -> Measurement Data > USL
  3. NG (NOT GOOD) -> Lower Range -> Measurement Data < LSL

Image 2

In my simple Control Chart, USL /LSL is used for verifying the data.USL -> Upper Specification Limit and LSL -> Lower Specification Limit. Note in this sample, I have used USL/LSL.

Difference between USL/LSL and UCL/LCL.

(The UCL or upper control limit and LCL or lower control limit are limits set by your process based on the actual amount of variation of your process.)

The USL or upper specification limit and LSL or lower specification limit are limits set by your customer's requirements. This is the variation that they will accept from your process. Reference)

I have been working on several automation projects. Instead of using third-party tools, I planned to create a simple program using .NET for creating a USL/LSL Control Bar chart for master setting. The main purpose of this article is to share what I have developed to other members.

I have created a Control Chart as a User Control so that it can be used easily in all projects.

In this article, I have attached the zip file named as SHANUControlChart_SRC.zip which contains:

  1. "SHANUControlChart_CNT" folder (This folder contains the Control Chart User control Source code.)
  2. "SHANUControlChart_DEMO" folder (This folder contains the Demo program which includes the Control Chart user control with Random Measurement sample using Timer control).

Using the Code

  1. First, we will start with the User Control. To create a user control:
    1. Create a new Windows Control Library project.
    2. Set the Name of Project and Click Ok (here, my user control name is SHANUControlChart_CNT).
    3. Add all the controls which are needed.
    4. In code behind, declare all the public variables and Public property variables. Here, USL/LSL/Nominal and Measurement Data Public property has been declared which will be used to pass the data from the windows application.
      VB.NET
      'Public Property Declaration
         Public Property MasterData() As String
             Get
                 Return lblMasterData.Text
             End Get
             Set(value As String)
                 lblMasterData.Text = value
             End Set
         End Property
      
         Public Property USLData() As String
             Get
                 Return lblUslData.Text
             End Get
             Set(value As String)
                 lblUslData.Text = value
             End Set
         End Property
      
         Public Property LSLData() As String
             Get
                 Return lblLslData.Text
             End Get
             Set(value As String)
                 lblLslData.Text = value
             End Set
         End Property
      
      
         Public Property NominalData() As String
             Get
                 Return lblNominalData.Text
             End Get
             Set(value As String)
                 lblNominalData.Text = value
             End Set
         End Property
      
    5. In my User control, I have used Timer control to always check for the Measurement data and produce the Bar Chart. In user control Load, I have Enabled and Start the Timer. In Timer Tick Event, I called the Function "LoadcontrolChart()". In this function, I set all USL/LSL and measurement data and draw the Chart control.
      VB.NET
      Public Sub LoadcontrolChart()
              Try
                  'For Bar and GageLoad
                  upperLimitChk = False
                  lowerLimitchk = False
                  errLimtchk = False
                  Dim pointVal As Integer
                  Dim calcvalues As Double
                  Dim calcvalues1 As Double
                  '  Dim upperValue As Double
                  Dim hasread As Integer
                  Dim UpperRange As Double
                  Dim err As String
                  pointVal = 3
                  Dim ival As Integer
      
                  sensordata = Convert.ToDouble(lblMasterData.Text.Trim())
      
                  frmMasteringPictuerBox.Refresh()
      
                  upperValue = System.Convert.ToDouble(lblUslData.Text)
                  lovervalue = System.Convert.ToDouble(lblLslData.Text)
                  If upperValue = lovervalue Then
                      lovervalue = lovervalue - 1
                  End If
      
                  inputValue = System.Convert.ToDouble(lblMasterData.Text)
                  'here we call the draw rectangle function 
                  drawRectanles(barheight, barwidth, upperValue, lovervalue, 
                                loverInitialvalue, upperInititalvalue, xval, yval)
                
      
              Catch ex As Exception
              End Try
          End Sub

      In this method, we check the Measurement data with USL and LSL Limit Value. If Measurement data is within the range of USL and LSL, then the resultant output will be Ok. I have used the if condition to check the resultant values as below:

      VB.NET
       ''This method is to draw the control chart 
          Public Sub drawRectanles(ByVal barheight As Double, ByVal barwidth As Double, _
                ByVal uppervalue As Double, ByVal lovervalue As Double, _
                ByVal loverinitialvalue As Double, ByVal upperinitialvalue As Double, _
                ByVal xval As Double, ByVal yval As Double)
              Try
                  Dim limitsline As Double
                  Dim lowerlimitline As Double
                  Dim underrange As Double
                  Dim upperrange As Double
                  Dim differentpercentage As Double
                  Dim totalheight As Double
                  Dim inputvalueCal As Double
                  Dim finaldisplayvalue As Double
                  Dim backColors1 As Color
                  Dim backColors2 As Color
                  'this is for the range percentage Calculation
                  differentpercentage = uppervalue - lovervalue
                  differentpercentage = differentpercentage * 0.2
                  'Upper range value
                  upperrange = uppervalue + differentpercentage
                  'Lover range value
                  underrange = lovervalue - differentpercentage
                  totalheight = upperrange - underrange
                  'For Upper Limit
                  ''limitsline = barheight * 0.2 - 10
                  limitsline = lovervalue - underrange
                  limitsline = limitsline / totalheight
                  limitsline = barheight * limitsline + 10
                  'For Lower Limit
                  lowerlimitline = uppervalue - underrange
                  lowerlimitline = lowerlimitline / totalheight
                  lowerlimitline = barheight * lowerlimitline + 10
                  'lowerlimitline = barheight - limitsline + 10
                  'for finding the rangedata
                  inputvalueCal = inputValue - underrange
                  finaldisplayvalue = inputvalueCal / totalheight
                  finaldisplayvalue = barheight * finaldisplayvalue
                  Dim g As Graphics = frmMasteringPictuerBox.CreateGraphics
                  Dim f5 As Font
                  f5 = New Font("arial", 22, FontStyle.Bold, GraphicsUnit.Pixel)
                  ''If condition to check for the result and display 
                  ''the chart accordingly depend on limit values.
                  If inputValue = "0.000" Then
                      If zeroDisplay = 0 Then
                          backColors1 = Color.Red
                          backColors2 = Color.DarkRed
                          Dim a5 As New System.Drawing.Drawing2D.LinearGradientBrush_
                             (New RectangleF(0, 0, 90, 19), backColors1, backColors2, _
                              Drawing.Drawing2D.LinearGradientMode.Horizontal)
                          g.DrawString("NG -> UnderRange", f5, a5, 
                                        System.Convert.ToInt32(xval) - 40, _
                                 barheight + 24)
                          lblMasterData.ForeColor = Color.Red
      
                          frmMasteringlblmsg.Text = "NG -> UnderRange"
                      Else
                          backColors1 = Color.GreenYellow
                          backColors2 = Color.DarkGreen
                          Dim a5 As New System.Drawing.Drawing2D.LinearGradientBrush_
                                 (New RectangleF(0, 0, 90, 19), backColors1, backColors2, _
                                  Drawing.Drawing2D.LinearGradientMode.Horizontal)
                          g.DrawString("OK -> Good", f5, a5, _
                                 System.Convert.ToInt32(xval) - 40, barheight + 24)
                          lblMasterData.ForeColor = Color.GreenYellow
      
                          frmMasteringlblmsg.Text = "OK -> Good"
                      End If
                  ElseIf inputValue >= lovervalue And inputValue <= uppervalue Then
                      backColors1 = Color.GreenYellow
                      backColors2 = Color.DarkGreen
                      If upperLimitChk = False Then
                          backColors1 = Color.GreenYellow
                          backColors2 = Color.DarkGreen
                          lblMasterData.ForeColor = Color.GreenYellow
                      Else
                          backColors1 = Color.Red
                          backColors2 = Color.DarkRed
                          lblMasterData.ForeColor = Color.Red
                      End If
                      Dim a5 As New System.Drawing.Drawing2D.LinearGradientBrush_
                            (New RectangleF(0, 0, 100, 19), backColors1, backColors2, _
                             Drawing.Drawing2D.LinearGradientMode.Horizontal)
                      g.DrawString("OK -> Good", f5, a5, 
                                    System.Convert.ToInt32(xval) - 40, barheight + 24)
      
                      frmMasteringlblmsg.Text = "OK -> Good"
                      'frmMasteringlblOrignalData.ForeColor = Color.GreenYellow
                  ElseIf inputValue < lovervalue Then
                      backColors1 = Color.Red
                      backColors2 = Color.DarkRed
                      Dim a5 As New System.Drawing.Drawing2D.LinearGradientBrush_
                           (New RectangleF(0, 0, 100, 19), backColors1, backColors2, _
                            Drawing.Drawing2D.LinearGradientMode.Horizontal)
                      g.DrawString("NG -> UnderRange", f5, 
                                    a5, System.Convert.ToInt32(xval) - 40, _
                            barheight + 24)
                      lblMasterData.ForeColor = Color.Red
                      'frmMasteringlblOrignalData.ForeColor = Color.Red
      
                      frmMasteringlblmsg.Text = "NG -> UnderRange"
                  ElseIf inputValue > uppervalue Then
                      backColors1 = Color.Red
                      backColors2 = Color.DarkRed
                      Dim a5 As New System.Drawing.Drawing2D.LinearGradientBrush_
                          (New RectangleF(0, 0, 100, 19), backColors1, backColors2, _
                          Drawing.Drawing2D.LinearGradientMode.Horizontal)
                      g.DrawString("NG -> UpperRange", f5, a5, 
                                   System.Convert.ToInt32(xval) - 40, _
                          barheight + 24)
                      lblMasterData.ForeColor = Color.Red
                      'frmMasteringlblOrignalData.ForeColor = Color.Red
      
                      frmMasteringlblmsg.Text = "NG -> UpperRange"
                  Else
                      backColors1 = Color.Red
                      backColors2 = Color.DarkRed
                      Dim a5 As New System.Drawing.Drawing2D.LinearGradientBrush_
                         (New RectangleF(0, 0, 100, 19), backColors1, backColors2, _
                          Drawing.Drawing2D.LinearGradientMode.Horizontal)
                      g.DrawString("Not Good", f5, a5, _
                                    System.Convert.ToInt32(xval) - 40, barheight + 24)
                      lblMasterData.ForeColor = Color.Red
      
                      frmMasteringlblmsg.Text = "Not Good"
                  End If
              
                  Dim apen As New Pen(Color.Black, 2)
                  g.DrawRectangle(Pens.Black, System.Convert.ToInt32(xval) - 2, _
                        System.Convert.ToInt32(yval) - 2, System.Convert.ToInt32(barwidth) + 3, _
                        System.Convert.ToInt32(barheight) + 3)
      
                  g.DrawLine(apen, System.Convert.ToInt32(xval) - 15, _
                                       System.Convert.ToInt32(limitsline), _
                  System.Convert.ToInt32(xval), System.Convert.ToInt32(limitsline))
                  g.DrawLine(apen, System.Convert.ToInt32(xval) - 15, _
                                       System.Convert.ToInt32(lowerlimitline), _
                  System.Convert.ToInt32(xval), System.Convert.ToInt32(lowerlimitline))
                  Dim a1 As New System.Drawing.Drawing2D.LinearGradientBrush_
                                      (New RectangleF(0, 0, 100, 19), _
                  Color.Blue, Color.Orange, Drawing.Drawing2D.LinearGradientMode.Horizontal)
                  Dim f As Font
                  f = New Font("arial", 10, FontStyle.Bold, GraphicsUnit.Pixel)
                  g.DrawString((String.Format("{0:N3}", CDbl(uppervalue.ToString))), _
                  f, a1, System.Convert.ToInt32(xval) - 40, _
                                     System.Convert.ToInt32(limitsline) + 1)
                  g.DrawString((String.Format("{0:N3}", CDbl(lovervalue.ToString))), _
                  f, a1, System.Convert.ToInt32(xval) - 40, _
                                     System.Convert.ToInt32(lowerlimitline) + 1)
                  g.DrawString((String.Format("{0:N3}", CDbl(upperrange.ToString))), _
                  f, a1, System.Convert.ToInt32(xval) - 40, 9)
                  g.DrawString((String.Format("{0:N3}", CDbl(underrange.ToString))), _
                  f, a1, System.Convert.ToInt32(xval) - 40, barheight + 10)
                  Dim a As New System.Drawing.Drawing2D.LinearGradientBrush(New RectangleF_
                  (xval, barheight + 10, barwidth, finaldisplayvalue + 1), backColors1, _
                  backColors2, Drawing.Drawing2D.LinearGradientMode.Vertical)
                
                  Dim a2 As New System.Drawing.Drawing2D.LinearGradientBrush_
                                 (New RectangleF(0, 0, 100, 19), _
                  Color.Black, Color.Black, Drawing.Drawing2D.LinearGradientMode.Horizontal)
                  Dim f2 As Font
                  f2 = New Font("arial", 12, FontStyle.Bold, GraphicsUnit.Pixel)
                  If inputValue >= upperrange Then
                      g.FillRectangle(a, New RectangleF(xval, 10, barwidth, barheight))
                      g.DrawString((String.Format("{0:N3}", CDbl(inputValue.ToString))), _
                      f2, a2, System.Convert.ToInt32(xval) + 40, yval - 8)
                  ElseIf inputValue <= underrange Then
                      g.FillRectangle(a, New RectangleF(xval, barheight + 10, barwidth, 4))
                      g.DrawString((String.Format("{0:N3}", CDbl(inputValue.ToString))), _
                      f2, a2, System.Convert.ToInt32(xval) + 40, barheight + 10)
                  Else
                      g.FillRectangle(a, New RectangleF_
                      (xval, barheight - finaldisplayvalue + 10, barwidth, finaldisplayvalue))
                      g.DrawString((String.Format("{0:N3}", CDbl(inputValue.ToString))), _
                      f2, a2, System.Convert.ToInt32(xval) + 40, _
                             barheight - System.Convert.ToInt32(finaldisplayvalue))
                  End If
                  ' End If
                  g.Dispose()
              Catch ex As Exception
              End Try
          End Sub
    6. After completion save, build and run the project.
  2. Now we create a Windows application and add and test our "SHANUControlChart_CNT" User Control.
    1. Create a new Windows project.
    2. Open your form and then from Toolbox > right click > choose items > browse select your user control DLL and add.
    3. Drag the User Control to your windows form.
    4. Place all the USL/LSL and Measurement Textbox for input from the user. In Manual check button click pass all the data to user control using the public property as below:
      VB.NET
      private void btnDisplay_Click(object sender, EventArgs e)
             {
                 shanuControlChart.USLData = txtusl.Text;
                 shanuControlChart.LSLData = txtLSL.Text;
                 shanuControlChart.NominalData = txtNominal.Text;
                 shanuControlChart.MasterData = txtData.Text;
             }
      
    5. In my demo program, I have used the Timer for the random sample Measurement data result checking. I have used the "btnRealTime" as Toggle button. When clicked for the first time, Enable and Start the Timer and same button is clicked again, Stop the Timer. When timer is Started, I have generated a random number and pass the different data to user control and check for the chart result.
      VB.NET
       private void btnRealTime_Click(object sender, EventArgs e)
              {
                  if (btnRealTime.Text == "Real Time Data ON")
                  {
                       btnRealTime.Text = "Real Time Data OFF";
                       btnRealTime.ForeColor = Color.Red;
                       timer1.Enabled = true;
                       timer1.Start();
                  }
                  else
                  {
                      btnRealTime.Text = "Real Time Data ON";
                      btnRealTime.ForeColor = Color.DarkGreen;
                      timer1.Enabled = false;
                      timer1.Stop();
                  }
              }
      
      // Timer Tick Event to check for the different random sample Measurement test data.
      
              private void timer1_Tick(object sender, EventArgs e)
              {
                 Random rnd =new Random();
      
              Double rndval = rnd.Next(1, 20);
      
              txtData.Text = rndval.ToString("0.000");//FormatNumber(rndval.ToString(), 3, , 0)
      
              shanuControlChart.USLData = txtusl.Text;
              shanuControlChart.LSLData = txtLSL.Text;
              shanuControlChart.NominalData = txtNominal.Text;
              shanuControlChart.MasterData = txtData.Text;
              }

Conclusion

The main aim of this article is to create a simple and standard Control Bar Chart user control for the automobile industry.

History

  • 2014/07/14: Initial release

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader
India India
Microsoft MVP | Code Project MVP | CSharp Corner MVP | Author | Blogger and always happy to Share what he knows to others. MyBlog

My Interview on Microsoft TechNet Wiki Ninja Link

Comments and Discussions

 
QuestionWho let this go through as article Pin
JustWatchLittle 15-Dec-17 10:00
professionalJustWatchLittle 15-Dec-17 10:00 
GeneralMy vote of 5 Pin
Santhakumar M17-Jan-16 20:49
professionalSanthakumar M17-Jan-16 20:49 
QuestionMy vote of 5 Pin
PSU Steve30-Jan-15 2:42
professionalPSU Steve30-Jan-15 2:42 
AnswerRe: My vote of 5 Pin
aarif moh shaikh7-Apr-15 18:47
professionalaarif moh shaikh7-Apr-15 18:47 
GeneralMy vote of 5 Pin
deshjibon15-Jul-14 9:12
deshjibon15-Jul-14 9:12 
GeneralRe: My vote of 5 Pin
syed shanu15-Jul-14 14:24
mvasyed shanu15-Jul-14 14:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.