Imports System.Drawing.Drawing2D
Imports System.Drawing
Public Class BDCC
Private bmp As Bitmap
#Region "介绍"
'类名:BDCC
'类全名:Benlee Drawing Chart Class
'类功能:绘制打印统计图表(暂时加入二维折线图)
'类版本号:1.0 Bate
'类开始编写日期:2003年8月15日
'类最后修改日期:2003年8月20日
#End Region
#Region "字段"
Private mintChartWidth As Integer = 0 '图片宽度
Private mintChartHeight As Integer = 0 '图片高度
Private mintContainerWidth As Integer = 0 '容器宽度
Private mintContainerHeight As Integer = 0 '容器高度
Private mobjContainer As New Object() '容器
Private mintChartPercenTage As Integer = 100 '图片与容器百分比
Private mintX_AxisColor As Color = Color.Black 'X坐标轴颜色
Private mintY_AxisColor As Color = Color.Black 'Y坐标轴颜色
Private mintX_AxisSize As Integer = 1 'X坐标轴大小
Private mintY_AxisSize As Integer = 1 'Y坐标轴大小
Private mintX_AxisLength As Integer 'X坐标轴长度
Private mintY_AxisLength As Integer 'Y坐标轴长度
Private mstrX_AxisLabel As String = "时间(s)" 'X坐标轴轴标
Private mstrY_AxisLabel_1 As String = "速度" 'Y坐标轴轴标_1
Private mstrY_AxisLabel_2 As String = "(km/h)" 'Y坐标轴轴标_2
Private mstrY_axislabel_3 As String = "制动信号" 'Y坐标轴轴标_3
Private mblnIsShowAxisLabel As Boolean = True '是否显示轴标
Private mblnIsShow_X_AxisScale As Boolean = True '是否显示X轴刻度
Private mblnIsShow_X_AxisSecondScale As Boolean = True '是否显示X轴次刻度
Private mblnIsShow_Y_AxisScale As Boolean = True '是否显示Y轴刻度
Private mintX_AxisFirstScale_Count As Integer = 20 'X坐标轴主刻度个数
Private mintX_AxisSecondScale_Count As Integer = 5 'X坐标轴次刻度个数
Private mintX_AxisScaleMaxValue As Integer = 100 'X坐标轴刻度最大值
Private mintY_AxisFirstScale_Count As Integer = 18 'Y坐标轴主刻度个数
Private mintY_AxisSecondScale_Count As Integer = 2 'Y坐标轴次刻度个数
Private mintY_AxisScaleMaxValue As Integer = 180 'Y坐标轴刻度最大值
Private mintX_AxisScaleLength As Integer 'X坐标轴刻度长度
Private mintY_AxisScaleLength As Integer 'Y坐标轴刻度长度
Private mintX_AxisFirstScalePerLength As Integer 'X坐标轴主刻度单位长度
Private mintY_AxisFirstScalePerLength As Integer 'Y坐标轴主刻度单位长度
Private mintX_AxisSecondScalePerLength As Integer 'X坐标轴次刻度单位长度
Private mintY_AxisSecondScalePerLength As Integer 'Y坐标轴次刻度单位长度
Private mintX_AxisFirstScaleColor As Color = Color.Black 'X坐标轴主刻度颜色
Private mintY_AxisFirstScaleColor As Color = Color.Black 'Y坐标轴主刻度颜色
Private mintX_AxisSecondScaleColor As Color = Color.Black 'X坐标轴次刻度颜色
Private mintY_AxisSecondScaleColor As Color = Color.Black 'Y坐标轴次刻度颜色
Private mblnIsShowX_AxisScaleLabel As Boolean = True '是否显示X轴上刻度标签
Private mblnIsShowY_AxisScaleLabel As Boolean = True '是否显示Y轴上刻度标签
Private mintX_AxisScaleLabelCount As Integer = 4 'X坐标轴上显示刻度标签个数
Private mintY_AxisScaleLabelCount As Integer = 18 'Y坐标轴上显示刻度标签个数
Private mintX_AxisScaleLabelColor As Color = Color.Black 'X坐标轴上刻度标签颜色
Private mintY_AxisScaleLabelColor As Color = Color.Black 'Y坐标轴上刻度标签颜色
Private mblnIsShowX_AxisSecondLine As Boolean = True '是否显示X坐标轴上的次轴线
Private mintX_AxisSecondLineColor As Color = Color.Black 'X坐标轴上的次轴线颜色
Private mintX_AxisSecondLineCount As Integer = 4 'X坐标轴上的次轴线个数
Private mblnIsShowDataLine As Boolean = True '是否显示数据线
Private mintDataLineSize As Integer = 1 '数据线大小
Private mintDataLineColor As Color = Color.Red '数据线颜色
Private mstrChartTitle As String = "事故疑点数据曲线" '图表标题
Private mblnIsShowChartTitle As Boolean = True '是否显示图表标题
Private mfntChartTitleFont As New Font("宋体", 9) '图表标题字体
Private mfntChartTitleFontColor As Color = Color.Black '图表标题字体颜色
Private mfntChartTitleAlign As TitleAlign = TitleAlign.TopCenter '图表标题对齐方式
Private mblnIsShowChartTitleNote As Boolean = True '是否显示图表标题注释
Private mstrCarNumber As String = "苏BA 000001" '车牌号
Private mstrCarClass As String = "大型汽车" '车牌分类
Private mstrDriverCardNumber As String = "320204198006281614" '驾驶证证号
Private mstrStopDate As String = Date.Today.ToString '停车时间
Private mfntChartTitleNoteFont As New Font("宋体", 9) '图表标题注释字体
Private mfntChartTitleNoteFontColor As Color = Color.Black '图表标题注释字体颜色
Private mobjGraphics As Graphics 'GDI+
Private mobjPen As Pen 'Pen
Private mintTopHeight As Integer '顶部高度
Private mdtChartData As New DataTable '图表数据
Private mdtOtherData As New DataTable '其它数据
Private mdtOpenValue As New DataTable '开关量
Private mstrfilename As String
#End Region
#Region "属性"
Public Property Container() As Object
Get
Return mobjContainer
End Get
Set(ByVal Value As Object)
mobjContainer = Value
mintContainerWidth = Value.width
mintContainerHeight = Value.height
End Set
End Property '容器
Public Property ChartPercenTage() As Integer
Get
Return mintChartPercenTage
End Get
Set(ByVal Value As Integer)
If Value >= 0 And Value <= 100 Then
mintChartPercenTage = Value
Else
Throw New ArgumentException("百分比数据不正确!")
mintChartPercenTage = 100
End If
End Set
End Property '图片与容器百分比
Public ReadOnly Property ChartWidth() As Integer
Get
Return CInt(mintContainerWidth * mintChartPercenTage / 100)
End Get
End Property '图片宽度
Public ReadOnly Property ChartHeight() As Integer
Get
Return CInt(mintContainerHeight * mintChartPercenTage / 100)
End Get
End Property '图片高度
Public Property X_AxisColor() As Color
Get
Return mintX_AxisColor
End Get
Set(ByVal Value As Color)
mintX_AxisColor = Value
End Set
End Property 'X坐标轴颜色
Public Property Y_AxisColor() As Color
Get
Return mintY_AxisColor
End Get
Set(ByVal Value As Color)
mintY_AxisColor = Value
End Set
End Property 'Y坐标轴颜色
Public Property X_AxisSize() As Integer
Get
Return mintX_AxisSize
End Get
Set(ByVal Value As Integer)
If Value > 0 And Value <= 5 Then
mintX_AxisSize = Value
Else
Throw New ArgumentException("坐标轴大小必须在1至5之间!")
mintX_AxisSize = 1
End If
End Set
End Property 'X坐标轴大小
Public Property Y_AxisSize() As Integer
Get
Return mintY_AxisSize
End Get
Set(ByVal Value As Integer)
If Value > 0 And Value <= 5 Then
mintY_AxisSize = Value
Else
Throw New ArgumentException("坐标轴大小必须在1至5之间!")
mintY_AxisSize = 1
End If
End Set
End Property 'Y坐标轴大小
Public Property IsShowAxisLabel() As Boolean
Get
Return mblnIsShowAxisLabel
End Get
Set(ByVal Value As Boolean)
mblnIsShowAxisLabel = Value
End Set
End Property '是否显示轴标
Public Property X_AxisFirstScale_Count() As Integer
Get
Return mintX_AxisFirstScale_Count
End Get
Set(ByVal Value As Integer)
mintX_AxisFirstScale_Count = Value
End Set
End Property 'X坐标轴主刻度个数
Public Property X_AxisSecondScale_Count() As Integer
Get
Return mintX_AxisSecondScale_Count
End Get
Set(ByVal Value As Integer)
mintX_AxisSecondScale_Count = Value
End Set
End Property 'X坐标轴次刻度个数
Public Property Y_AxisFirstScale_Count() As Integer
Get
Return mintY_AxisFirstScale_Count
End Get
Set(ByVal Value As Integer)
mintY_AxisFirstScale_Count = Value
End Set
End Property 'Y坐标轴主刻度个数
Public Property Y_AxisSecondScale_Count() As Integer
Get
Return mintY_AxisSecondScale_Count
End Get
Set(ByVal Value As Integer)
mintY_AxisSecondScale_Count = Value
End Set
End Property 'Y坐标轴次刻度个数
Public ReadOnly Property X_AxisScaleLength() As Integer
Get
Return mintX_AxisScaleLength
End Get
End Property 'X坐标轴刻度长度
Public Property X_AxisScaleMaxValue() As Integer
Get
Return mintX_AxisScaleMaxValue
End Get
Set(ByVal Value As Integer)
mintX_AxisScaleMaxValue = Value
End Set
End Property 'X坐标轴刻度最大值
Public ReadOnly Property Y_AxisScaleLength() As Integer
Get
Return mintY_AxisScaleLength
End Get
End Property 'Y坐标轴刻度长度
Public Property Y_AxisScaleMaxValue() As Integer
Get
Return mintY_AxisScaleMaxValue
End Get
Set(ByVal Value As Integer)
mintY_AxisScaleMaxValue = Value
End Set
End Property 'Y坐标轴刻度最大值
Public ReadOnly Property X_AxisFirstScalePerLength() As Integer
Get
Return mintX_AxisFirstScalePerLength
End Get
End Property 'X坐标轴主刻度单位长度
Public ReadOnly Property Y_AxisFirstScalePerLength() As Integer
Get
Return mintY_AxisFirstScalePerLength
End Get
End Property 'Y坐标轴主刻度单位长度
Public ReadOnly Property X_AxisSecondScalePerLength() As Integer
Get
Return mintX_AxisSecondScalePerLength
End Get
End Property 'X坐标轴次刻度单位长度
Public ReadOnly Property Y_AxisSecondScalePerLength() As Integer
Get
Return mintY_AxisSecondScalePerLength
End Get
End Property 'Y坐标轴次刻度单位长度
Public Property X_AxisFirstScaleColor() As Color
Get
Return mintX_AxisFirstScaleColor
End Get
Set(ByVal Value As Color)
mintX_AxisFirstScaleColor = Value
End Set
End Property 'X坐标轴主刻度颜色
Public Property Y_AxisFirstScaleColor() As Color
Get
Return mintY_AxisFirstScaleColor
End Get
Set(ByVal Value As Color)
mintY_AxisFirstScaleColor = Value
End Set
End Property 'Y坐标轴主刻度颜色
Public Property X_AxisSecondScaleColor() As Color
Get
Return mintX_AxisSecondScaleColor
End Get
Set(ByVal Value As Color)
mintX_AxisSecondScaleColor = Value
End Set
End Property 'X坐标轴次刻度颜色
Public Property Y_AxisSecondScaleColor() As Color
Get
Return mintY_AxisSecondScaleColor
End Get
Set(ByVal Value As Color)
mintY_AxisSecondScaleColor = Value
End Set
End Property 'Y坐标轴次刻度颜色
Public Property IsShowX_AxisScaleLabel() As Boolean
Get
Return mblnIsShowX_AxisScaleLabel
End Get
Set(ByVal Value As Boolean)
mblnIsShowX_AxisScaleLabel = Value
End Set
End Property '是否显示X轴刻度标签
Public Property IsShowY_AxisScaleLabel() As Boolean
Get
Return mblnIsShowY_AxisScaleLabel
End Get
Set(ByVal Value As Boolean)
mblnIsShowY_AxisScaleLabel = Value
End Set
End Property '是否显示Y轴刻度标签
Public Property IsShow_X_AxisSecondScale() As Boolean
Get
Return mblnIsShow_X_AxisSecondScale
End Get
Set(ByVal Value As Boolean)
mblnIsShow_X_AxisSecondScale = Value
End Set
End Property '是否显示X轴次刻度
Public Property X_AxisScaleLabelCount() As Integer
Get
Return mintX_AxisScaleLabelCount
End Get
Set(ByVal Value As Integer)
If ((mintX_AxisFirstScale_Count * mintX_AxisSecondScale_Count) Mod Value) = 0 Then
mintX_AxisScaleLabelCount = Value
Else
Throw New ArgumentException("刻度标签个数不正确!")
mintX_AxisScaleLabelCount = 4
End If
End Set
End Property 'X坐标轴上显示刻度标签个数
Public Property Y_AxisScaleLabelCount() As Integer
Get
Return mintY_AxisScaleLabelCount
End Get
Set(ByVal Value As Integer)
If ((mintY_AxisFirstScale_Count * mintY_AxisSecondScale_Count) Mod Value) = 0 Then
mintY_AxisScaleLabelCount = Value
Else
Throw New ArgumentException("刻度标签个数不正确!")
mintY_AxisScaleLabelCount = 4
End If
End Set
End Property 'Y坐标轴上显示刻度标签个数
Public Property X_AxisScaleLabelColor() As Color
Get
Return mintX_AxisScaleLabelColor
End Get
Set(ByVal Value As Color)
mintX_AxisScaleLabelColor = Value
End Set
End Property 'X坐标轴上刻度标签颜色
Public Property Y_AxisScaleLabelColor() As Color
Get
Return mintY_AxisScaleLabelColor
End Get
Set(ByVal Value As Color)
mintY_AxisScaleLabelColor = Value
End Set
End Property 'Y坐标轴上刻度标签颜色
Public Property IsShowX_AxisSecondLine() As Boolean
Get
Return mblnIsShowX_AxisSecondLine
End Get
Set(ByVal Value As Boolean)
mblnIsShowX_AxisSecondLine = Value
End Set
End Property '是否显示X坐标轴上的次轴线
Public Property X_AxisSecondLineColor() As Color
Get
Return mintX_AxisSecondLineColor
End Get
Set(ByVal Value As Color)
mintX_AxisSecondLineColor = Value
End Set
End Property 'X坐标轴上的次轴线颜色
Public Property X_AxisSecondLineCount() As Integer
Get
Return mintX_AxisSecondLineCount
End Get
Set(ByVal Value As Integer)
If (mintX_AxisFirstScale_Count * mintX_AxisSecondScale_Count) Mod mintX_AxisSecondLineCount = 0 Then
mintX_AxisSecondLineCount = Value
Else
Throw New ArgumentException("次轴个数必须能被刻度总数整除!")
mintX_AxisSecondLineCount = mintX_AxisFirstScale_Count
End If
End Set
End Property 'X坐标轴上的次轴个数
Public Property IsShowDataLine() As Boolean
Get
Return mblnIsShowDataLine
End Get
Set(ByVal Value As Boolean)
mblnIsShowDataLine = Value
End Set
End Property '是否显示数据线
Public Property DataLineSize() As Integer
Get
Return mintDataLineSize
End Get
Set(ByVal Value As Integer)
mintDataLineSize = Value
End Set
End Property '数据线大小
Public Property DataLineColor() As Color
Get
Return mintDataLineColor
End Get
Set(ByVal Value As Color)
mintDataLineColor = Value
End Set
End Property '数据线颜色
Public Property ChartTitle() As String
Get
Return mstrChartTitle
End Get
Set(ByVal Value As String)
mstrChartTitle = Value
End Set
End Property '图表标题
Public Property IsShowChartTitle() As Boolean
Get
Return mblnIsShowChartTitle
End Get
Set(ByVal Value As Boolean)
mblnIsShowChartTitle = Value
End Set
End Property '是否显示图表标题
Public Property ChartTitleFont() As Font
Get
Return mfntChartTitleFont
End Get
Set(ByVal Value As Font)
If (Value.SizeInPoints > 0) And (Value.SizeInPoints <= 15) Then
mfntChartTitleFont = Value
Else
Throw New ArgumentException("标题字体大小必须在1至15之间!")
mfntChartTitleFont = New Font("宋体", 9)
End If
End Set
End Property '图表标题字体
Public Property ChartTitleFontColor() As Color
Get
Return mfntChartTitleFontColor
End Get
Set(ByVal Value As Color)
mfntChartTitleFontColor = Value
End Set
End Property '图表标题字体颜色
Public Property ChartTitleAlign() As TitleAlign
Get
Return mfntChartTitleAlign
End Get
Set(ByVal Value As TitleAlign)
mfntChartTitleAlign = Value
End Set
End Property '图表标题对齐方式
Public Property IsShowChartTitleNote() As Boolean
Get
Return mblnIsShowChartTitleNote
End Get
Set(ByVal Value As Boolean)
mblnIsShowChartTitleNote = Value
End Set
End Property '是否显示图表标题注释
Public Property CarNumber() As String
Get
Return mstrCarNumber
End Get
Set(ByVal Value As String)
mstrCarNumber = Value
End Set
End Property '车牌号
Public Property CarClass() As String
Get
Return mstrCarClass
End Get
Set(ByVal Value As String)
mstrCarClass = Value
End Set
End Property '车牌分类
Public Property DriverCardNumber() As String
Get
Return mstrDriverCardNumber
End Get
Set(ByVal Value As String)
mstrDriverCardNumber = Value
End Set
End Property '驾驶证证号
Public Property StopDate() As String
Get
Return mstrStopDate
End Get
Set(ByVal Value As String)
mstrStopDate = Value
End Set
End Property '停车时间
Public Property ChartTitleNoteFont() As Font
Get
Return mfntChartTitleNoteFont
End Get
Set(ByVal Value As Font)
If (Value.SizeInPoints > 0) And (Value.SizeInPoints <= 15) Then
mfntChartTitleNoteFont = Value
Else
Throw New ArgumentException("标题字体大小必须在1至15之间!")
mfntChartTitleNoteFont = New Font("宋体", 9)
End If
End Set
End Property '图表标题注释字体
Public Property ChartTitleNoteFontColor() As Color
Get
Return mfntChartTitleNoteFontColor
End Get
Set(ByVal Value As Color)
mfntChartTitleNoteFontColor = Value
End Set
End Property '图表标题注释字体颜色
Public ReadOnly Property Graphics() As Graphics
Get
Return mobjGraphics
End Get
End Property 'GDI+
Public ReadOnly Property filename() As String
Get
Return mstrfilename
End Get
End Property '文件名称
#End Region
#Region "结构"
#End Region
#Region "枚举"
Public Enum TitleAlign
TopLeft = 1
MiddleLeft = 2
ButtomLeft = 3
TopCenter = 4
MiddleCenter = 5
ButtomCenter = 6
TopRight = 7
MiddleRight = 8
ButtomRight = 9
End Enum '对齐方式
#End Region
#Region "事件"
#End Region
#Region "方法"
Private Sub New()
Try
Catch ex As Exception
main.errmessage = New frmerrmessage("程序出现异常,无法正常运行!", "错误编码:A00032")
main.errmessage.ShowDialog()
End Try
End Sub '构造函数
Public Sub New(ByVal tempdata As DataTable, ByVal otherdata As DataTable, ByVal OpenValue As DataTable)
Me.New()
Try
mdtChartData = tempdata.Copy '线条数据
mdtOpenValue = OpenValue.Copy
mdtOtherData = otherdata '其它相关数据
Catch ex As Exception
main.errmessage = New frmerrmessage("程序出现异常,无法正常运行!", "错误编码:A00033")
main.errmessage.ShowDialog()
End Try
End Sub '构造函数(带参数,参数为数据表)
Public Sub New(ByVal array_1 As ArrayList, ByVal array_2 As ArrayList)
'增加数组转数据表的代码
Try
Catch ex As Exception
main.errmessage = New frmerrmessage("程序出现异常,无法正常运行!", "错误编码:A00034")
main.errmessage.ShowDialog()
End Try
End Sub '构造函数(带参数,参数为数组)
Public Sub DrawChart_2D_XY()
Try
'Dim b As Image
bmp = New Bitmap(mintContainerWidth, mintContainerHeight)
Graphics.FromImage(bmp).Clear(Color.White)
'Dim i, j As Integer
'For i = 0 To bmp.Width - 1
' For j = 0 To bmp.Height - 1
' If bmp.GetPixel(i, j).Black.ToString() = Color.Black.ToString Then
' bmp.SetPixel(i, j, Color.White)
' End If
' Next
'Next
If mblnIsShowChartTitle Then '如果显示图表标题
DrawChart_2D_XY_Title(Graphics.FromImage(bmp))
'DrawChart_2D_XY_Title(mobjContainer.CreateGraphics)
End If
If mblnIsShowChartTitleNote Then '如果显示图表标题注释
DrawChart_2D_XY_TitleNote(Graphics.FromImage(bmp))
'DrawChart_2D_XY_TitleNote(mobjContainer.CreateGraphics)
End If
DrawChart_2D_XY_Axis_XY(Graphics.FromImage(bmp))
'DrawChart_2D_XY_Axis_XY(mobjContainer.CreateGraphics)
If mblnIsShowAxisLabel Then '如果显示坐标轴标
DrawChart_2D_XY_AxisLabel(Graphics.FromImage(bmp))
'DrawChart_2D_XY_AxisLabel(mobjContainer.CreateGraphics)
End If
If mblnIsShow_X_AxisScale Then '如果显示X轴刻度
DrawChart_2D_XY_X_AxisScale(Graphics.FromImage(bmp))
'DrawChart_2D_XY_X_AxisScale(mobjContainer.CreateGraphics)
End If
If mblnIsShow_Y_AxisScale Then '如果显示Y轴刻度
DrawChart_2D_XY_Y_AxisScale(Graphics.FromImage(bmp))
'DrawChart_2D_XY_Y_AxisScale(mobjContainer.CreateGraphics)
End If
If mblnIsShowX_AxisSecondLine Then '如果显示X轴上的次轴线
DrawChart_2D_XY_X_AxisSecondLine(Graphics.FromImage(bmp))
'DrawChart_2D_XY_X_AxisSecondLine(mobjContainer.CreateGraphics)
End If
If mblnIsShowX_AxisScaleLabel Then '如果显示X轴上的刻度标签
DrawChart_2D_XY_X_AxisScaleLabel(Graphics.FromImage(bmp))
'DrawChart_2D_XY_X_AxisScaleLabel(mobjContainer.CreateGraphics)
End If
If mblnIsShowY_AxisScaleLabel Then '如果显示Y轴上的刻度标签
DrawChart_2D_XY_Y_AxisScaleLabel(Graphics.FromImage(bmp))
'DrawChart_2D_XY_Y_AxisScaleLabel(mobjContainer.CreateGraphics)
End If
If mblnIsShowDataLine Then '如果显示数据线
DrawChart_2D_XY_DataLine(Graphics.FromImage(bmp))
'DrawChart_2D_XY_DataLine(mobjContainer.CreateGraphics)
End If
If Not (mdtOtherData Is Nothing) Then '如果有其它数据
DrawChart_2D_XY_DataLine_OtherData(Graphics.FromImage(bmp))
'DrawChart_2D_XY_DataLine_OtherData(mobjContainer.CreateGraphics)
End If
mstrfilename = Date.Now.Year & "_" & Date.Now.Month & "_" & Date.Now.Day & "_" & Date.Now.Hour & "_" & Date.Now.Minute & "_" & Date.Now.Second
mstrfilename = Application.StartupPath & "/picture/" & mstrfilename & ".jpeg"
If Dir(Application.StartupPath & "/picture", FileAttribute.Directory) <> "picture" Then
System.IO.Directory.CreateDirectory(Application.StartupPath & "/picture")
End If
bmp.Save(mstrfilename, System.Drawing.Imaging.ImageFormat.Jpeg)
Catch ex As Exception
main.errmessage = New frmerrmessage("程序出现异常,无法正常运行!", "错误编码:A00035")
main.errmessage.ShowDialog()
End Try
End Sub '绘制二维折线图
Private Sub DrawChart_2D_XY_Title(ByVal TempGraphics As Graphics)
Try
Dim X, Y As Integer '坐标X,Y
Dim TopHeight As Integer '顶部高度
mobjGraphics = TempGraphics
Select Case mfntChartTitleAlign
Case TitleAlign.TopLeft
X = 5
Y = 5
Case TitleAlign.TopCenter
X = CInt((mobjContainer.width / 2) - ((mstrChartTitle.Length / 2) * (mfntChartTitleFont.Size * 1.4)))
Y = 5
Case TitleAlign.TopRight
X = mobjContainer.width - 5
Y = 5
Case TitleAlign.MiddleLeft
X = 5
Y = CInt((mobjContainer.height / 2) - (mfntChartTitleFont.Height * 1.4 / 2))
Case TitleAlign.MiddleCenter
X = CInt((mobjContainer.width / 2) - ((mstrChartTitle.Length / 2) * (mfntChartTitleFont.Size * 1.4)))
Y = CInt((mobjContainer.height / 2) - (mfntChartTitleFont.Height * 1.4 / 2))
Case TitleAlign.MiddleRight
X = (mobjContainer.width - 5)
Y = CInt((mobjContainer.height / 2) - (mfntChartTitleFont.Height * 1.4 / 2))
Case TitleAlign.ButtomLeft
X = 5
Y = (mobjContainer.height - 5)
Case TitleAlign.ButtomCenter
X = ((mobjContainer.width / 2) - ((mstrChartTitle.Length / 2) * (mfntChartTitleFont.Size * 1.4)))
Y = (mobjContainer.height - 5)
Case TitleAlign.ButtomRight
X = (mobjContainer.width - 5)
Y = (mobjContainer.height - 5)
End Select
mobjGraphics.DrawString(mstrChartTitle, mfntChartTitleFont, New SolidBrush(mfntChartTitleFontColor), X, Y)
Catch ex As Exception
main.errmessage = New frmerrmessage("程序出现异常,无法正常运行!", "错误编码:A00036")
main.errmessage.ShowDialog()
End Try
End Sub '绘制图表标题
Private Sub DrawChart_2D_XY_TitleNote(ByVal TempGraphics As Graphics)
Try
Dim X_1, Y_1, X_2, Y_2 As Integer
Dim TopHeight As Integer '顶部高度
Dim noteline_1, noteline_2 As String
noteline_1 = "车牌号:" & mstrCarNumber & " 车牌分类:" & mstrCarClass
noteline_2 = "驾驶证证号:" & mstrDriverCardNumber & " 停车时间: " & mstrStopDate
mobjGraphics = TempGraphics
TopHeight = 5 + (mfntChartTitleFont.Height)
X_1 = CInt((mobjContainer.width / 2) - ((noteline_1.Length / 2) * (mfntChartTitleNoteFont.Size * 1.4)))
Y_1 = CInt(TopHeight + mfntChartTitleNoteFont.Height / 2)
mobjGraphics.DrawString(noteline_1, mfntChartTitleNoteFont, New SolidBrush(mfntChartTitleNoteFontColor), X_1, Y_1)
TopHeight = 5 + (mfntChartTitleFont.Height) + (mfntChartTitleNoteFont.Height)
X_2 = mobjContainer.width - noteline_2.Length * mfntChartTitleNoteFont.Size * 1.25
'X_2 = CInt((mobjContainer.width / 2) - ((noteline_2.Length / 2) * (mfntChartTitleNoteFont.Size * 1.4)))
Y_2 = CInt(TopHeight + mfntChartTitleNoteFont.Height / 2)
mobjGraphics.DrawString(noteline_2, mfntChartTitleNoteFont, New SolidBrush(mfntChartTitleNoteFontColor), X_2, Y_2)
Catch ex As Exception
main.errmessage = New frmerrmessage("程序出现异常,无法正常运行!", "错误编码:A00037")
main.errmessage.ShowDialog()
End Try
End Sub '绘制图表注释
Private Sub DrawChart_2D_XY_Axis_XY(ByVal TempGraphics As Graphics)
Try
Dim X_1, Y_1, X_2, Y_2 As Integer '坐标轴两个点的坐标
Dim Point_1, Point_2, Point_3 As Point '坐标轴头上的小三角的三个点的坐标
Dim TrigonPoint As Point() '三角形项点坐标集
Dim newFillMode As FillMode = FillMode.Winding '填充模式
mintTopHeight = 5
If mblnIsShowChartTitle Then '如果显示图表标题
mintTopHeight += (mfntChartTitleFont.Height)
End If
If mblnIsShowChartTitleNote Then '如果显示图表标题注释
mintTopHeight += (mfntChartTitleNoteFont.Height) * 2
End If
mobjPen = New Pen(mintX_AxisColor, mintX_AxisSize)
mobjGraphics = TempGraphics
'绘制Y轴
X_1 = 70
Y_1 = mintTopHeight + 30
X_2 = 70
Y_2 = mobjContainer.height - 10
mintX_AxisLength = Y_2 - Y_1 '记录Y轴长度
mobjGraphics.DrawLine(mobjPen, X_1, Y_1, X_2, Y_2)
'绘制Y轴顶部三角形
Point_1 = New Point(X_1, Y_1 + 25)
Point_2 = New Point(X_1 - 4, Y_1 + 45)
Point_3 = New Point(X_1 + 4, Y_1 + 45)
TrigonPoint = New Point() {Point_1, Point_2, Point_3}
mobjGraphics.FillPolygon(New SolidBrush(mintX_AxisColor), TrigonPoint)
'绘制X轴
X_1 = 30
Y_1 = mobjContainer.height - 30
X_2 = mobjContainer.width - 50
Y_2 = mobjContainer.height - 30
mobjGraphics.DrawLine(mobjPen, X_1, Y_1, X_2, Y_2)
'绘制X轴顶部三角形
Point_1 = New Point(X_2 + 5, Y_2)
Point_2 = New Point(X_2 - 15, Y_2 - 4)
Point_3 = New Point(X_2 - 15, Y_2 + 4)
TrigonPoint = New Point() {Point_1, Point_2, Point_3}
mobjGraphics.FillPolygon(New SolidBrush(mintX_AxisColor), TrigonPoint)
'绘制坐标原点0
X_1 = 56
Y_1 = mobjContainer.height - 26
mobjGraphics.DrawString("0", New Font("宋体", 9), New SolidBrush(mintX_AxisColor), X_1, Y_1)
Catch ex As Exception
main.errmessage = New frmerrmessage("程序出现异常,无法正常运行!", "错误编码:A00038")
main.errmessage.ShowDialog()
End Try
End Sub '绘制坐标轴
Private Sub DrawChart_2D_XY_AxisLabel(ByVal TempGraphics As Graphics)
Try
Dim X_1, Y_1 As Integer
mobjGraphics = TempGraphics
'绘制X轴轴标
X_1 = mobjContainer.width - 80
Y_1 = mobjContainer.height - 22
mobjGraphics.DrawString(mstrX_AxisLabel, New Font("宋体", 9), New SolidBrush(mintX_AxisColor), X_1, Y_1)
'绘制Y轴轴标_1
X_1 = 30
Y_1 = mintTopHeight + 55
mobjGraphics.DrawString(mstrY_AxisLabel_1, New Font("宋体", 9), New SolidBrush(mintX_AxisColor), X_1, Y_1)
'绘制Y轴轴标_2
X_1 = 10
Y_1 = mintTopHeight + 70
mobjGraphics.DrawString(mstrY_AxisLabel_2, New Font("宋体", 9), New SolidBrush(mintX_AxisColor), X_1, Y_1)
'绘制Y轴轴标_3
X_1 = 10
Y_1 = mintTopHeight + 35
mobjGraphics.DrawString(mstrY_axislabel_3, New Font("宋体", 9), New SolidBrush(mintX_AxisColor), X_1, Y_1)
Catch ex As Exception
main.errmessage = New frmerrmessage("程序出现异常,无法正常运行!", "错误编码:A00039")
main.errmessage.ShowDialog()
End Try
End Sub '绘制坐标轴轴标
Private Sub DrawChart_2D_XY_X_AxisScale(ByVal TempGraphics As Graphics)
Try
Dim X_1, Y_1, X_2, Y_2 As Integer
Dim iLoop As Integer
mobjGraphics = TempGraphics
mintX_AxisScaleLength = mobjContainer.width - 85 - 70
mintX_AxisSecondScalePerLength = mintX_AxisScaleLength / (mintX_AxisFirstScale_Count * mintX_AxisSecondScale_Count)
'次刻度单位长度 = X轴长度 / (主刻度数 * 次刻度数)
mintX_AxisFirstScalePerLength = mintX_AxisSecondScalePerLength * mintX_AxisSecondScale_Count
'主刻度单位长度 = 次刻度单位长度 * 次刻度数
X_1 = 70
Y_1 = mobjContainer.height - 30
X_2 = 70
Y_2 = mobjContainer.height - 20
For iLoop = 1 To mintX_AxisFirstScale_Count * mintX_AxisSecondScale_Count
X_1 += mintX_AxisSecondScalePerLength
X_2 = X_1
If iLoop Mod mintX_AxisSecondScale_Count = 0 Then
mobjGraphics.DrawLine(New Pen(mintX_AxisFirstScaleColor), X_1, Y_1, X_2, Y_2)
Else
If mblnIsShow_X_AxisSecondScale Then
mobjGraphics.DrawLine(New Pen(mintX_AxisSecondScaleColor), X_1, Y_1, X_2, Y_2 - 5)
End If
End If
Next
Catch ex As Exception
main.errmessage = New frmerrmessage("程序出现异常,无法正常运行!", "错误编码:A00040")
main.errmessage.ShowDialog()
End Try
End Sub '绘制坐标轴X轴刻度
Private Sub DrawChart_2D_XY_Y_AxisScale(ByVal TempGraphics As Graphics)
Try
Dim X_1, Y_1, X_2, Y_2 As Integer
Dim iLoop As Integer
mobjGraphics = TempGraphics
mintY_AxisScaleLength = (mobjContainer.height - 30) - (mintTopHeight + 90)
mintY_AxisSecondScalePerLength = mintY_AxisScaleLength / (mintY_AxisFirstScale_Count * mintY_AxisSecondScale_Count)
mintY_AxisFirstScalePerLength = mintY_AxisSecondScalePerLength * mintY_AxisSecondScale_Count
X_1 = 60
Y_1 = mobjContainer.height - 30
X_2 = 70
Y_2 = mobjContainer.height - 30
For iLoop = 1 To mintY_AxisFirstScale_Count * mintY_AxisSecondScale_Count
Y_1 -= mintY_AxisSecondScalePerLength
Y_2 = Y_1
If iLoop Mod mintY_AxisSecondScale_Count = 0 Then
mobjGraphics.DrawLine(New Pen(mintY_AxisFirstScaleColor), X_1, Y_1, X_2, Y_2)
Else
mobjGraphics.DrawLine(New Pen(mintY_AxisSecondScaleColor), X_1 + 5, Y_1, X_2, Y_2)
End If
Next
Catch ex As Exception
main.errmessage = New frmerrmessage("程序出现异常,无法正常运行!", "错误编码:A00041")
main.errmessage.ShowDialog()
End Try
End Sub '绘制坐标轴Y轴刻度
Private Sub DrawChart_2D_XY_X_AxisSecondLine(ByVal TempGraphics As Graphics)
Try
Dim X_1, Y_1, X_2, Y_2 As Integer
Dim iLoop As Integer
Dim PerLength As Integer
mobjGraphics = TempGraphics
mobjPen = New Pen(mintX_AxisSecondLineColor)
mobjPen.DashStyle = DashStyle.DashDot
PerLength = (mintX_AxisFirstScale_Count * mintX_AxisSecondScale_Count / mintX_AxisSecondLineCount) * mintX_AxisSecondScalePerLength
X_1 = 70
Y_1 = mintTopHeight + 30
X_2 = 70
Y_2 = mobjContainer.height - 30
For iLoop = 1 To mintX_AxisSecondLineCount
X_1 += PerLength
X_2 = X_1
mobjGraphics.DrawLine(mobjPen, X_1, Y_1, X_2, Y_2)
Next
Catch ex As Exception
main.errmessage = New frmerrmessage("程序出现异常,无法正常运行!", "错误编码:A00042")
main.errmessage.ShowDialog()
End Try
End Sub '绘制坐标轴X轴上的次轴线
Private Sub DrawChart_2D_XY_X_AxisScaleLabel(ByVal TempGraphics As Graphics)
Try
Dim X_1, Y_1 As Integer
Dim iLoop As Integer
Dim PerLength As Integer
mobjGraphics = TempGraphics
PerLength = (mintX_AxisFirstScale_Count * mintX_AxisSecondScale_Count / mintX_AxisScaleLabelCount) * mintX_AxisSecondScalePerLength - 2
X_1 = 70
Y_1 = mobjContainer.height - 20
For iLoop = 1 To mintX_AxisScaleLabelCount
X_1 += PerLength
mobjGraphics.DrawString(iLoop * (mintX_AxisFirstScale_Count / mintX_AxisScaleLabelCount), New Font("宋体", 9), New SolidBrush(mintX_AxisScaleLabelColor), X_1, Y_1)
Next
Catch ex As Exception
main.errmessage = New frmerrmessage("程序出现异常,无法正常运行!", "错误编码:A00043")
main.errmessage.ShowDialog()
End Try
End Sub '绘制X轴上的刻度标签
Private Sub DrawChart_2D_XY_Y_AxisScaleLabel(ByVal TempGraphics As Graphics)
Try
Dim X_1, Y_1 As Integer
Dim iLoop As Integer
Dim PerLength As Integer
mobjGraphics = TempGraphics
PerLength = (mintX_AxisFirstScale_Count * mintY_AxisSecondScale_Count / mintY_AxisScaleLabelCount) * mintY_AxisSecondScalePerLength
X_1 = 30
Y_1 = mobjContainer.height - 34
For iLoop = 1 To mintY_AxisScaleLabelCount
Y_1 -= PerLength
mobjGraphics.DrawString(iLoop * (mintY_AxisFirstScale_Count / mintY_AxisScaleLabelCount) * 10, New Font("宋体", 9), New SolidBrush(mintY_AxisScaleLabelColor), X_1, Y_1)
Next
Catch ex As Exception
main.errmessage = New frmerrmessage("程序出现异常,无法正常运行!", "错误编码:A00044")
main.errmessage.ShowDialog()
End Try
End Sub '绘制Y轴上的刻度标签
Private Sub DrawChart_2D_XY_DataLine(ByVal TempGraphics As Graphics)
Try
Dim X_1, Y_1, X_2, Y_2, X_3, Y_3, X_4, Y_4 As Integer
Dim iLoop_1, iLoop_2 As Integer
mobjGraphics = TempGraphics
For iLoop_1 = 0 To mdtChartData.Rows.Count - 2
If iLoop_1 > mintX_AxisFirstScale_Count * mintX_AxisSecondScale_Count Then
'超出X轴刻度总数时,结束绘制
Exit For
End If
'------------------------------------------------------------------------------------------
'此处是为了弥补由于第一个数据是落在Y轴上的,所以将数据右移一个单位,在Y轴上用第一个元素来填充
If iLoop_1 = 0 Then
For iLoop_2 = 0 To mdtChartData.Columns.Count - 1
X_1 = 70 + (iLoop_1) * mintX_AxisSecondScalePerLength
If mdtChartData.Rows(iLoop_1).Item(iLoop_2) > mintY_AxisScaleMaxValue Then
Y_1 = mobjContainer.height - 30 - mintY_AxisSecondScale_Count * mintY_AxisFirstScale_Count * mintY_AxisSecondScalePerLength - 10
ElseIf mdtChartData.Rows(iLoop_1).Item(iLoop_2) < 0 Then
Y_1 = 0
Else
Y_1 = mobjContainer.height - 30 - mdtChartData.Rows(iLoop_1).Item(iLoop_2) * mintY_AxisSecondScalePerLength / (mintY_AxisScaleMaxValue / (mintY_AxisFirstScale_Count * mintY_AxisSecondScale_Count))
End If
X_2 = 70 + (iLoop_1 + 1) * mintX_AxisSecondScalePerLength
Y_2 = Y_1
If iLoop_2 Mod 2 = 0 Then
mobjGraphics.DrawLine(New Pen(mintDataLineColor), X_1, Y_1, X_2, Y_2)
Else
mobjGraphics.DrawLine(New Pen(Color.Blue), X_1, Y_1, X_2, Y_2)
End If
Next
End If
'----------------------------------------------------------------------------------------------
For iLoop_2 = 0 To mdtChartData.Columns.Count - 1
X_1 = 70 + (iLoop_1 + 1) * mintX_AxisSecondScalePerLength
If mdtChartData.Rows(iLoop_1).Item(iLoop_2) > mintY_AxisScaleMaxValue Then
Y_1 = mobjContainer.height - 30 - mintY_AxisSecondScale_Count * mintY_AxisFirstScale_Count * mintY_AxisSecondScalePerLength - 10
ElseIf mdtChartData.Rows(iLoop_1).Item(iLoop_2) < 0 Then
Y_1 = 0
Else
Y_1 = mobjContainer.height - 30 - mdtChartData.Rows(iLoop_1).Item(iLoop_2) * mintY_AxisSecondScalePerLength / (mintY_AxisScaleMaxValue / (mintY_AxisFirstScale_Count * mintY_AxisSecondScale_Count))
End If
X_2 = 70 + (iLoop_1 + 2) * mintX_AxisSecondScalePerLength
If mdtChartData.Rows(iLoop_1 + 1).Item(iLoop_2) > mintY_AxisScaleMaxValue Then
Y_1 = mobjContainer.height - 30 - mintY_AxisSecondScale_Count * mintY_AxisFirstScale_Count * mintY_AxisSecondScalePerLength - 10
ElseIf mdtChartData.Rows(iLoop_1 + 1).Item(iLoop_2) < 0 Then
Y_2 = 0
Else
Y_2 = mobjContainer.height - 30 - mdtChartData.Rows(iLoop_1 + 1).Item(iLoop_2) * mintY_AxisSecondScalePerLength / (mintY_AxisScaleMaxValue / (mintY_AxisFirstScale_Count * mintY_AxisSecondScale_Count))
End If
If iLoop_2 Mod 2 = 0 Then
mobjGraphics.DrawLine(New Pen(mintDataLineColor, 1), X_1, Y_1, X_2, Y_2)
If mdtOpenValue.Rows(iLoop_1)(0) = "+" Then
'此处为制动信号
X_3 = 70 + (iLoop_1 + 1) * mintX_AxisSecondScalePerLength
Y_3 = mintTopHeight + 40
X_4 = 70 + (iLoop_1 + 2) * mintX_AxisSecondScalePerLength
Y_4 = Y_3
'此处为画制动信号
mobjGraphics.DrawLine(New Pen(Color.Black), X_3, Y_3, X_4, Y_4)
End If
Else
mobjGraphics.DrawLine(New Pen(Color.Blue), X_1, Y_1, X_2, Y_2)
End If
Next
Next
Catch ex As Exception
main.errmessage = New frmerrmessage("程序出现异常,无法正常运行!", "错误编码:A00045")
main.errmessage.ShowDialog()
End Try
End Sub '绘制图表数据线
Private Sub DrawChart_2D_XY_DataLine_OtherData(ByVal Tempgraphics As Graphics)
Try
Catch ex As Exception
main.errmessage = New frmerrmessage("程序出现异常,无法正常运行!", "错误编码:A00046")
main.errmessage.ShowDialog()
End Try
End Sub '绘制其它数据(制动信息)
Public Sub DrawChart_2D_XY_Print(ByVal ParaGraphics As Graphics)
Try
mobjGraphics = ParaGraphics
If mblnIsShowChartTitle Then '如果显示图表标题
DrawChart_2D_XY_Title(mobjGraphics)
End If
If mblnIsShowChartTitleNote Then '如果显示图表标题注释
DrawChart_2D_XY_TitleNote(mobjGraphics)
End If
DrawChart_2D_XY_Axis_XY(mobjGraphics)
If mblnIsShowAxisLabel Then '如果显示坐标轴标
DrawChart_2D_XY_AxisLabel(mobjGraphics)
End If
If mblnIsShow_X_AxisScale Then '如果显示X轴刻度
DrawChart_2D_XY_X_AxisScale(mobjGraphics)
End If
If mblnIsShow_Y_AxisScale Then '如果显示Y轴刻度
DrawChart_2D_XY_Y_AxisScale(mobjGraphics)
End If
If mblnIsShowX_AxisSecondLine Then '如果显示X轴上的次轴线
DrawChart_2D_XY_X_AxisSecondLine(mobjGraphics)
End If
If mblnIsShowX_AxisScaleLabel Then '如果显示X轴上的刻度标签
DrawChart_2D_XY_X_AxisScaleLabel(mobjGraphics)
End If
If mblnIsShowY_AxisScaleLabel Then '如果显示Y轴上的刻度标签
DrawChart_2D_XY_Y_AxisScaleLabel(mobjGraphics)
End If
If mblnIsShowDataLine Then '如果显示数据线
DrawChart_2D_XY_DataLine(mobjGraphics)
End If
Catch ex As Exception
main.errmessage = New frmerrmessage("程序出现异常,无法正常运行!", "错误编码:A00047")
main.errmessage.ShowDialog()
End Try
End Sub '打印二维折线图
#End Region
End Class