Imports system.drawing.drawing2dimports system.drawing 'Drawing Chart PUBLIC CLASS CLASSDRAWCHART
#Region "field" total frequency detecting Private mData As ArrayList 'data Private mItemName As ArrayList' project name detected Private mintCount As Integer 'number data Private mintAllTestCount As Integer' Private mType As ClassTest.TestType 'type Private mBmp As Bitmap' pattern Private MIMAGESTREAM As System.io.MemoryStream 'Graphics stream private mintwidth as integer = 1080' wide private mintheight as integer = 740 'high private gdi as graphics' gdi # End Region
#Region "Properties" PUBLIC READONLY PROPERTY Image () AS Bitmap 'Graphic Get Return MBMP End Get Property
Public Readonly Property ImageStream () as system.io.MemoryStream 'Graphic stream Get Return MimageStream End Get Property # End Region
#Region "Method" Public Sub New (ByVal Data As ArrayList, ByVal ItemName As ArrayList, ByVal Type As ClassTest.TestType, ByVal AllTestCoun As Integer) 'constructor mData = Data mItemName = ItemName mintCount = Data.Count mType = Type mintAllTestCount = AllTestCoun End Sub 'configured Public Sub drawing () Try' drawn mBmp = New Bitmap (mintWidth, mintHeight) mImageStream = New System.IO.MemoryStream GDI = Graphics.FromImage (mBmp) GDI.Clear (Color.White) 'to draw the title DrawingTitle (mType, GDI) 'drawing axis DrawingXYAxis (mType, GDI)' a histogram DrawingChart (mType, GDI) 'to save the chart memory mBmp.Save (mImageStream, Imaging.ImageFormat.Bmp) Catch ex As Exception Debug.WriteLine (EX.TOSTRING) ClassComm.writeerrMessage (ex. scrodring, "classdrawchart_drawing) End Try End Sub 'Drawing Private Sub DrawingTitle (ByVal Type As ClassTest.TestType, ByVal GDI As Graphics) Try' to draw the title Dim Title As String Dim TitleFont As New Font ( "Arial", 12, FontStyle.Bold) Dim X, Y As Integer Select Case Type Case Classtest.TestType.CarComputer Title = "Body Computer Unqualified Statistics Chart" Case Classtest.testtype.CompositeMeter Title = "Combined Meter Unqualified Chart" End Select X = (MintWidth - TitleFont.Size * Title.length * 1.4) / 2 y =
22 GDI.DrawString (Title, TitleFont, New SolidBrush (Color.Black), X, Y) Catch ex As Exception Debug.WriteLine (ex.ToString) ClassComm.WriteErrMessage (ex.ToString, "ClassDrawChart_DrawingTitle") End Try End Sub ' draw the title Private Sub DrawingXYAxis (ByVal Type As ClassTest.TestType, ByVal GDI As Graphics) Try 'axis plotted Dim XAxis_X1, XAxis_Y1, XAxis_X2, XAxis_Y2 As Integer' X-axis coordinate Dim YAxis_X1, YAxis_Y1, YAxis_X2, YAxis_Y2 As Integer 'Y-axis Coordinate DIM POINT_1, POINT_2, POINT_3 AS Point 'Triangle Coordinate DIM TrigonPoint As Point ()' Triangle Coordinate Dim Trigonbrush As New Solidbrush (Color.Black) 'Brush DIM LINEPEN AS New Pen (Color.Black, 2) XAXIS_X1 = 20 XAXIS_X2 = MINTWIDTH - 20 XAXIS_Y1 = MINTHEIGHT - 50 x Axis_Y2 = XAxis_Y1 GDI.DrawLine (LinePen, XAxis_X1, XAxis_Y1, XAxis_X2, XAxis_Y2) 'X-axis Point_1 = New Point (XAxis_X2, XAxis_Y1) Point_2 = New Point (XAxis_X2 - 15, XAxis_Y1 - 5) Point_3 = New Point (XAxis_X2 - 15 , XAxis_Y1 5) TrigonPoint = New Point () {point_1, point_2, Point_3} GDI.FillPolygon (TrigonBrush, TrigonPoint) 'X-axis triangular YAxis_X1 = 40 YAxis_X2 = YAxis_X1 YAxis_Y1 = 50 YAxis_Y2 = mintHeight - 30 GDI.DrawLine (LinePen, YAXIS_X1, YAXIS_Y1, YAXIS_X2, YAXIS_Y2) '
Y-axis Point_1 = New Point (YAxis_X1, YAxis_Y1) Point_2 = New Point (YAxis_X1 - 5, YAxis_Y1 15) Point_3 = New Point (YAxis_X1 5, YAxis_Y1 15) TrigonPoint = New Point () {Point_1, Point_2, Point_3} GDI.FillPolygon (TrigonBrush, TrigonPoint) 'X-axis triangular Catch ex As Exception Debug.WriteLine (ex.ToString) ClassComm.WriteErrMessage (ex.ToString, "ClassDrawChart_DrawingXYAxis") End Try End Sub' axis plotted Private Sub DrawingChart (ByVal type As ClassTest.TestType, ByVal GDI As Graphics) 'a histogram Try Dim PerWidth, PerHeight, AllWidth, AllHeight As Integer Dim iLoop As Integer Dim X1, Y1, X2, Y2, X, Y, Width, Height As Integer Dim RectangleBrush As New Hatchbrush (Hatchstyle.BackwardDiagonal, Color.Red, Color.White) Dim Rectanglepen As new Pen (Color.red) Dim DataFont AS New Font ("Song", 9) Dim Titlefont As New Font ("Song Body", 9) DIM TITLEDRAWFORMAT AS New StringFormat Allwidth = MintWidth - 40 - 20 - 15 - 20 'Draw Column Of Y-axis Lear Leeds Allheight = MintHeight - 50 - 15 - 20 - 30 - 20 x1 = 40 Y1 = mintHeight - 50 X2 = mintWidth - 20 - 15 - 20 Y2 = Y1 PerWidth = (X2 - X1) / mintCount PerHeight = AllHeight / mintAllTestCount Width = PerWidth / 3 'drawn For iLoop = 0 To mintCount - 1' drawing Columnal Figure IF MDATA (ILOOP) = 0 THEN X =
X1 (Perwidth * 2/3) (Perwidth * iLOOP) Y = Y2 Height = 10 gdi.fillRectangle (Rectanglebrush, x, y, width, height) gdi.drawRectangle (Rectanglepen, x, y, width, height) ELSE X = x1 (Perwidth * 2/3) (Perwidth * iLoop) Y = Y2 - (Perheight * MData (iLOOP) HEIGHT = perheight * mdata (iLOOP) GDI.FillRectangle (Rectanglebrush, x, y, width, Height ) Gdi.drawrecTangle (Rectanglepen, x, y, width, height) endiff 'Draw Digital Select Case MData (iLOOP) .tostring.Length Case 1' 1 digit gdi.drawstring (mdata (iLoop), DataFont, New Solidbrush ( Color.red, X, Y - DataFont.Height) Case 2 '2 digit gdi.drawstring (MData (iLoop), DataFont, New SO Lidbrush (Color.red), X - DataFont.Size / 2, Y - DataFont.Height) Case 3 '3 digit gdi.drawstring (mdata (iLOOP), DataFont, New Solidbrush (Color.red), X - DataFont. Size * 2/3, Y - DataFont.Height) End Select 'Title drawn TitleDrawFormat.FormatFlags = StringFormatFlags.DirectionVertical GDI.DrawString (mItemName (iLoop), TitleFont, New SolidBrush (Color.Blue), (X1
(PerWidth * iLoop)), (Y1 - mItemName (iLoop) .ToString.Length * TitleFont.Height), TitleDrawFormat) Next Catch ex As Exception Debug.WriteLine (ex.ToString) ClassComm.WriteErrMessage (ex.ToString, "ClassDrawChart_DrawingChart" ) END TRY End Sub 'Painting Publi.DrawImage (MBMP, 0, 0) Catch EX ASTOSTRING (EX.TOSTRING) CATE GDI.DRAWIMAGE (EX.TOSTRING) , "Classdrawchart_print") End Try End Sub 'Print Chart #END Regionend Class