Imports Microsoft.VisualBasic Imports System.Data Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Drawing.Imaging Imports System.Web.UI Public Class LineChartAbs Public b As Bitmap Public Title As String = "Default Title" Public chartValues As ArrayList = New ArrayList Public chartValues2 As ArrayList = New ArrayList Public chartValues3 As ArrayList = New ArrayList Public Xorigin As Single = 0 Public Yorigin As Single = 0 Public ScaleX As Single Public ScaleY As Single Public Xdivs As Single = 2 Public Ydivs As Single = 2 Private Width As Integer Private Height As Integer Private g As Graphics Private p As Page Private btn As Button Structure datapoint Public x As Single Public y As Single Public xCaption As String Public yCaption As String Public ATTRAVERAGE As String Public valid As Boolean End Structure Public Sub New(ByVal myWidth As Integer, ByVal myHeight As Integer, ByVal myPage As Page) Width = myWidth Height = myHeight ScaleX = myWidth ScaleY = myHeight b = New Bitmap(myWidth, myHeight) g = Graphics.FromImage(b) p = myPage End Sub Public Sub AddValue(ByVal x As Integer, ByVal y As Double, ByVal xCaption As String, ByVal yCaption As String) Dim myPoint As datapoint = New datapoint() myPoint.x = x myPoint.y = y myPoint.xCaption = xCaption myPoint.yCaption = yCaption myPoint.valid = True chartValues.Add(myPoint) End Sub Public Sub AddValue2(ByVal x As Integer, ByVal y As Double, ByVal xCaption As String, ByVal yCaption As String) Dim myPoint As datapoint = New datapoint() myPoint.x = x myPoint.y = y myPoint.xCaption = xCaption myPoint.yCaption = yCaption myPoint.valid = True chartValues2.Add(myPoint) End Sub Public Sub AddValue3(ByVal x As Integer, ByVal y As Double, ByVal xCaption As String, ByVal yCaption As String) Dim myPoint As datapoint = New datapoint() myPoint.x = x myPoint.y = y myPoint.xCaption = xCaption myPoint.yCaption = yCaption myPoint.valid = True chartValues3.Add(myPoint) End Sub Public Sub AddValue(ByVal x As Integer, ByVal y As Double) AddValue(x, y, x.ToString, y.ToString()) End Sub Public Sub DisplayValues() Dim i As Integer Dim Labelvalue As String Dim blackBrushN As Brush = New SolidBrush(Color.Black) Dim axesFontN As Font = New Font("arial", 10) Dim ChartInset As Integer = 500 Dim ChartWidth As Integer = Width - (2 * ChartInset) Dim ChartHeight As Integer = Height - (2 * ChartInset) For i = 0 To chartValues.Count If i >= chartValues.Count Then Labelvalue = "" Else Labelvalue = CType(chartValues(i), datapoint).xCaption Labelvalue = Labelvalue & "-" & CType(chartValues(i), datapoint).yCaption g.DrawString(Labelvalue, axesFontN, blackBrushN, Width + 1, Height) End If Next For i = 0 To chartValues2.Count If i >= chartValues2.Count Then Labelvalue = "" Else Labelvalue = CType(chartValues2(i), datapoint).xCaption Labelvalue = Labelvalue & "-" & CType(chartValues2(i), datapoint).yCaption g.DrawString(Labelvalue, axesFontN, blackBrushN, Width + 1, Height) End If Next For i = 0 To chartValues3.Count If i >= chartValues3.Count Then Labelvalue = "" Else Labelvalue = CType(chartValues3(i), datapoint).xCaption Labelvalue = Labelvalue & "-" & CType(chartValues3(i), datapoint).yCaption g.DrawString(Labelvalue, axesFontN, blackBrushN, Width + 1, Height) End If Next End Sub 'Public Sub Draw(ByVal filename As String) Public Sub Draw(ByVal sol As String, ByVal ySol As Integer) Dim i As Integer Dim x As Single Dim y As Single Dim x0 As Single Dim y0 As Single Dim myLabel As String Dim blackPen As Pen = New Pen(Color.Black, 1) Dim RedPen As Pen = New Pen(Color.FromArgb(186, 5, 5), 1) Dim bluePen As Pen = New Pen(Color.Blue, 1) Dim greenPen As Pen = New Pen(Color.Chartreuse) Dim blueBrush As Brush = New SolidBrush(Color.Blue) Dim violetBrush As Brush = New SolidBrush(Color.Violet) Dim RedBrush As Brush = New SolidBrush(Color.FromArgb(109, 44, 0)) Dim MarunBrush As Brush = New SolidBrush(Color.FromArgb(109, 44, 0)) Dim blackBrush As Brush = New SolidBrush(Color.Black) Dim axesFont As Font = New Font("verdana", 8, FontStyle.Bold) Dim solFont As Font = New Font("verdana", 9, FontStyle.Bold) p.Response.ContentType = "image/jpeg" g.FillRectangle(New SolidBrush(Color.FromArgb(255, 216, 189)), 0, 0, Width, Height) Dim ChartInset As Integer = 50 Dim ChartWidth As Integer = Width - (2 * ChartInset) Dim ChartHeight As Integer = Height - (2 * ChartInset) g.DrawRectangle(New Pen(Color.Blue, 1), ChartInset, ChartInset, ChartWidth, ChartHeight) g.DrawString(sol & vbCrLf & " ", solFont, violetBrush, 70, ySol) btn = New Button btn.ID = "btnBack" btn.Text = "deepchand" g.DrawString(Title, New Font("verdana", 8, FontStyle.Bold), blueBrush, Width / 6, 5) i = 0 i = 0 While i <= Xdivs x = ChartInset + (i * ChartWidth) / Xdivs y = ChartHeight + ChartInset myLabel = (Xorigin + (ScaleX * i / Xdivs)).ToString If i = Xdivs Then Dim s1 As StringFormat = New StringFormat(StringFormatFlags.DirectionVertical) myLabel = "Iterations" & vbCrLf & " " g.DrawString(myLabel, axesFont, blueBrush, x - 30, y + 15) ElseIf (i Mod 10) = 0 Then g.DrawString(myLabel, axesFont, blackBrush, x, y + 5) Else myLabel = "" g.DrawString(myLabel, axesFont, blackBrush, x, y - 6) End If g.DrawLine(blackPen, x, y + 2, x, y - 2) System.Math.Min(System.Threading.Interlocked.Increment(i), i - 1) End While i = 0 i = 0 While i <= Ydivs x = ChartInset y = ChartHeight + ChartInset - (i * ChartHeight / Ydivs) myLabel = (Yorigin + (ScaleY * i / Ydivs)).ToString If i = Ydivs Then Dim s1 As StringFormat = New StringFormat(StringFormatFlags.DirectionVertical) myLabel = "Distance" g.DrawString(myLabel, axesFont, blueBrush, 15, y - 45, s1) ElseIf (i Mod 5) = 0 Then g.DrawString(myLabel, axesFont, blackBrush, 20, y - 6) Else myLabel = "" g.DrawString(myLabel, axesFont, blackBrush, 20, y - 6) End If g.DrawLine(blackPen, x + 2, y, x - 2, y) System.Math.Min(System.Threading.Interlocked.Increment(i), i - 1) End While g.RotateTransform(180) g.TranslateTransform(0, -Height) g.TranslateTransform(-ChartInset, ChartInset) g.ScaleTransform(-1, 1) Dim prevPoint As datapoint = New datapoint prevPoint.valid = False i = 0 For Each myPoint As datapoint In chartValues If prevPoint.valid = True Then x0 = ChartWidth * (prevPoint.x - Xorigin) / ScaleX y0 = ChartHeight * (prevPoint.y - Yorigin) / ScaleY x = ChartWidth * (myPoint.x - Xorigin) / ScaleX y = ChartHeight * (myPoint.y - Yorigin) / ScaleY g.DrawLine(bluePen, x0, y0, x, y) 'Removed points on graph KellyK 'g.FillEllipse(blueBrush, x0 - 2, y0 - 2, 6, 6) 'g.FillEllipse(blueBrush, x - 2, y - 2, 6, 6) End If prevPoint = myPoint i = i + 1 Next prevPoint.valid = False i = 0 For Each myPoint As datapoint In chartValues2 If prevPoint.valid = True Then x0 = ChartWidth * (prevPoint.x - Xorigin) / ScaleX y0 = ChartHeight * (prevPoint.y - Yorigin) / ScaleY x = ChartWidth * (myPoint.x - Xorigin) / ScaleX y = ChartHeight * (myPoint.y - Yorigin) / ScaleY g.DrawLine(greenPen, x0, y0, x, y) 'Removed points on graph KellyK 'g.FillEllipse(blueBrush, x0 - 2, y0 - 2, 6, 6) 'g.FillEllipse(blueBrush, x - 2, y - 2, 6, 6) End If prevPoint = myPoint i = i + 1 Next prevPoint.valid = False For Each myPoint As datapoint In chartValues3 If prevPoint.valid = True Then x0 = ChartWidth * (prevPoint.x - Xorigin) / ScaleX y0 = ChartHeight * (prevPoint.y - Yorigin) / ScaleY x = ChartWidth * (myPoint.x - Xorigin) / ScaleX y = ChartHeight * (myPoint.y - Yorigin) / ScaleY g.DrawLine(RedPen, x0, y0, x, y) 'Removed points on graph KellyK 'g.FillEllipse(blueBrush, x0 - 2, y0 - 2, 6, 6) 'g.FillEllipse(blueBrush, x - 2, y - 2, 6, 6) End If prevPoint = myPoint i = i + 1 Next b.Save(p.Response.OutputStream, ImageFormat.Jpeg) b.Dispose() End Sub Public Sub DrawAverage() Dim i As Integer Dim x As Single Dim y As Single Dim x0 As Single Dim y0 As Single Dim myLabel As String Dim d1 As String Dim m1 As String Dim blackPen As Pen = New Pen(Color.Black, 1) Dim bluePen As Pen = New Pen(Color.Blue, 1) Dim blueBrush As Brush = New SolidBrush(Color.Blue) Dim blackBrush As Brush = New SolidBrush(Color.Black) Dim axesFont As Font = New Font("verdana", 8, FontStyle.Bold) p.Response.ContentType = "image/jpeg" 'g.FillRectangle(New SolidBrush(Color.LightYellow), 0, 0, Width, Height) g.FillRectangle(New SolidBrush(Color.FromArgb(255, 216, 189)), 0, 0, Width, Height) 'Dim ChartInset As Integer = 50 old given for test change Dim ChartInset As Integer = 50 Dim ChartWidth As Integer = Width - (2 * ChartInset) Dim ChartHeight As Integer = Height - (2 * ChartInset) g.DrawRectangle(New Pen(Color.Blue, 1), ChartInset, ChartInset, ChartWidth, ChartHeight) 'g.DrawString(Title, New Font("arial", 14), blackBrush, Width / 3, 10) g.DrawString(Title, New Font("verdana", 8, FontStyle.Bold), blueBrush, Width / 6, 5) i = 0 i = 0 While i <= Xdivs x = ChartInset + (i * ChartWidth) / Xdivs y = ChartHeight + ChartInset ' This code Add for Print The X-axis values in Formate If i >= chartValues.Count Then myLabel = "Weeks->" & vbCrLf & " " 'g.DrawString(myLabel, axesFont, blueBrush, x - 17, y + 10) Else 'myLabel = CType(chartValues(i - 1), datapoint).xCaption change myLabel = CType(chartValues(i), datapoint).xCaption d1 = myLabel.Substring(0, 2).ToString m1 = myLabel.Substring(3, 3).ToString myLabel = d1 & vbCrLf & m1 End If g.DrawString(myLabel, axesFont, blackBrush, x - 8, y + 10) g.DrawLine(blackPen, x, y + 2, x, y - 2) If i < chartValues.Count And i >= 3 Then '' To Print the Average Attrition% on the dots myLabel = CType(chartValues(i), datapoint).ATTRAVERAGE x = (ChartWidth * (CType(chartValues(i), datapoint).x - Xorigin) / ScaleX) + ChartInset y = ChartHeight - (ChartHeight * (CType(chartValues(i), datapoint).y - Yorigin) / ScaleY) + ChartInset - 15 g.DrawString(myLabel, axesFont, blackBrush, x, y) ''End To Print the Average Attrition% on the dots End If System.Math.Min(System.Threading.Interlocked.Increment(i), i - 1) End While i = 0 i = 0 While i <= Ydivs x = ChartInset y = ChartHeight + ChartInset - (i * ChartHeight / Ydivs) myLabel = (Yorigin + (ScaleY * i / Ydivs)).ToString & "%" 'g.DrawString(myLabel, axesFont, blackBrush, 5, y - 6) old given for test change g.DrawString(myLabel, axesFont, blackBrush, 25, y - 6) g.DrawLine(blackPen, x + 2, y, x - 2, y) System.Math.Min(System.Threading.Interlocked.Increment(i), i - 1) End While g.RotateTransform(180) g.TranslateTransform(0, -Height) g.TranslateTransform(-ChartInset, ChartInset) g.ScaleTransform(-1, 1) Dim prevPoint As datapoint = New datapoint prevPoint.valid = False i = 0 For Each myPoint As datapoint In chartValues If prevPoint.valid = True Then x0 = ChartWidth * (prevPoint.x - Xorigin) / ScaleX y0 = ChartHeight * (prevPoint.y - Yorigin) / ScaleY x = ChartWidth * (myPoint.x - Xorigin) / ScaleX y = ChartHeight * (myPoint.y - Yorigin) / ScaleY 'If CType(chartValues(i), datapoint).ATTRAVERAGE.Trim > 0 Then 'g.DrawLine(bluePen, x0, y0, x, y) 'End If If i >= 3 Then g.DrawLine(bluePen, x0, y0, x, y) g.FillEllipse(blueBrush, x0 - 2, y0 - 2, 6, 6) g.FillEllipse(blueBrush, x - 2, y - 2, 6, 6) End If i = i + 1 End If 'myLabel = myPoint.yCaption 'g.DrawString(myLabel, axesFont, blackBrush, x0 + 1, y0 + 1) prevPoint = myPoint Next b.Save(p.Response.OutputStream, ImageFormat.Jpeg) End Sub Protected Overrides Sub Finalize() g.Dispose() b.Dispose() End Sub End Class