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.
Public Sub LoadcontrolChart()
Try
upperLimitChk = False
lowerLimitchk = False
errLimtchk = False
Dim pointVal As Integer
Dim calcvalues As Double
Dim calcvalues1 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)
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:
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
differentpercentage = uppervalue - lovervalue
differentpercentage = differentpercentage * 0.2
upperrange = uppervalue + differentpercentage
underrange = lovervalue - differentpercentage
totalheight = upperrange - underrange
limitsline = lovervalue - underrange
limitsline = limitsline / totalheight
limitsline = barheight * limitsline + 10
lowerlimitline = uppervalue - underrange
lowerlimitline = lowerlimitline / totalheight
lowerlimitline = barheight * lowerlimitline + 10
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 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"
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
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
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
g.Dispose()
Catch ex As Exception
End Try
End Sub