Click here to Skip to main content
12,449,891 members (34,817 online)
Click here to Skip to main content
Add your own
alternative version

Stats

17.3K views
1.1K downloads
29 bookmarked
Posted

Control Chart Using .Net

, 27 Jan 2015 CPOL
Rate this:
Please Sign up or sign in to vote.
USL/LSL Control Chart using .Net for Quality Control.

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 ,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 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

 

In my simple Control Chart USL /LSL are 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. Ref)

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 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 conains 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 is 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.
'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 Measurment data and produce the Bar Chart.In user control Load I have Enabled and Start the Timer.In Timer Tick Event called the Function "LoadcontrolChart()" .In this fucntion i set all USL/LSL and measurement data and draw the Chart control.

Public Sub LoadcontrolChart()
        Try
            'For Barand 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 ractangle fucntion 
            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 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 .

''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 persentage 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.
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 first time clicked Enabled and Start the Timer and same button clicked again Stop the Timer.When timer is Start i have generated a random no and pass the different data to user control and check for the chart result.

 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

Initial release on 2014/07/14.

License

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

Share

About the Author

syed shanu
Team Leader
India India

Microsoft MVP 2016


My Interview on Microsoft TechNet Wiki Ninja Link




His Blog


Syed Shanu is basically from Madurai, Tamil Nadu, India.He was been working in South Korea for past 8 years. He started programming with Basic Language and C language from his high school at 1999.In 2005 he completed his Master of Computer Application. He started his working Career from Dec 2004 with ASP.

He has 10+ years of Experience in Microsoft Technologies.

His work experience with Language and Technology start’s from ASP and SQL Server, Then VB.NET and C# for PDA Application, Touch Screen Application Development, Desktop Application, ASP.NET Web Application Development, MVC and WPF.

He loves to work with Microsoft technology as he started to work on .Net Frame Work version from 1.0 to 4.5.

He had worked with HMI (Human Machine Interface) programs like PLC, Nutrunner Tools, and Sensor programs, RFID programs, Barcode programs and etc.

He usually uses his free time to spend with his Family and go outing. He loves photography and Hiking.

ASP.NET Article of the Day

1) Title : Draw ASP.NET Bar Chart Using HTML5 and jQuery Date : July 8, 2015
2) Title : ASP.NET Web Photo Editing Tool using HTML 5 Date : July 8, 2015
3) Title : MVC AngularJS and WCF Rest Service For Mind Reader Quiz Date : May 18, 2015
4) Title : AngularJS Shopping Cart Using MVC and WCF Rest Service Date : April 10, 2015
5) Title : Insert select update delete in asp.net with Simple Log
6) Title : Project Scheduling Using ASP.Net GridView Date : December 26, 2014
7) Title : ASP.NET Web Painting Tool using HTML 5 Date : September 16, 2014

You may also be interested in...

Pro
Pro

Comments and Discussions

 
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
memberPSU 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
memberdeshjibon15-Jul-14 9:12 
GeneralRe: My vote of 5 Pin
syed shanu15-Jul-14 14:24
membersyed 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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160826.1 | Last Updated 28 Jan 2015
Article Copyright 2015 by syed shanu
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid