Imports FlexCell Imports Steema.TeeChart Public Class Form1 Public filepath As String Public GdbConnString As String Public linglist As Dictionary(Of String, Steema.TeeChart.Styles.Line) Private _axis As List(Of Steema.TeeChart.Axis) Private _fastLine As Dictionary(Of String, Steema.TeeChart.Styles.FastLine) Private _curSor(1) As Steema.TeeChart.Tools.CursorTool Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load filepath = $"{Application.StartupPath }\config.flx" GdbConnString = "Server=blv-cloud-db.mysql.rds.aliyuncs.com;Port=3307;Database=mqqtmysql;Uid=blv_rcu;Pwd=fnadiaJDIJ7546;charset=utf8;" _axis = New List(Of Axis) _fastLine = New Dictionary(Of String, Styles.FastLine) init_Grid_config() FileTo_Grid_config() linglist = New Dictionary(Of String, Steema.TeeChart.Styles.Line) 'initChartBar(10, 1701747214, 1704822658) 'Testfunction() 'ksjfk() End Sub Private Sub InitPieChart(kkdic As Dictionary(Of String, Dictionary(Of Long, Double)), starttime As Long, stoptime As Long) InitTeeChart(kkdic, starttime, stoptime) Dim fl As Steema.TeeChart.Styles.FastLine Dim tval As Dictionary(Of Long, Double) Dim dtOffset As New DateTimeOffset(New DateTime(1970, 1, 1, 0, 0, 0)) ' 获取本地日期和时间 Dim yt As DateTime For t = starttime To stoptime For Each node In kkdic fl = _fastLine.Item(node.Key) tval = node.Value yt = (dtOffset.AddSeconds(t)).LocalDateTime If tval.ContainsKey(t) Then If t = starttime OrElse Not (tval.Item(t) = tval.Item(t - 1)) Then Else fl.Add(yt.ToOADate, tval.Item(t - 1)) 'Console.WriteLine($"{yt.ToOADate}:{ tval.Item(t - 1)}") End If fl.Add(yt.ToOADate, tval.Item(t)) 'Console.WriteLine($"{yt.ToOADate}:{ tval.Item(t)}") ''Console.WriteLine(DateTime.FromOADate(yt.ToOADate).ToString("yyyy-MM-dd HH:mm:ss")) '#1/16/2024 01:09:47 AM# Else If t < tval.Keys(0) Then If tval.Values(0) = 1 Then fl.Add(yt.ToOADate, 0) tval.Add(t, 0) 'Console.WriteLine($"{yt.ToOADate}:0") ElseIf tval.Values(0) = 0 Then fl.Add(yt.ToOADate, 1) tval.Add(t, 1) 'Console.WriteLine($"{yt.ToOADate}:1") Else fl.Add(yt.ToOADate, 0.5) tval.Add(t, 0.5) 'Console.WriteLine($"{yt.ToOADate}:0.5") End If Else If tval.Item(t - 1) = 1 Then fl.Add(yt.ToOADate, 1) tval.Add(t, 1) 'Console.WriteLine($"{yt.ToOADate}:1") ElseIf tval.Item(t - 1) = 0 Then fl.Add(yt.ToOADate, 0) tval.Add(t, 0) 'Console.WriteLine($"{yt.ToOADate}:0") Else fl.Add(yt.ToOADate, 0.5) tval.Add(t, 0.5) 'Console.WriteLine($"{yt.ToOADate}:0.5") End If End If End If Next Next End Sub Public Sub initChartBar(tCounta As Integer, starttime As Double, stoptime As Double) 'Dim devline = AddTeeChartStylesLine() ChartBar.Header.Text = "" '标题 ChartBar.Header.Visible = True ChartBar.Legend.Transparent = False '刻印说明 ' ChartBar.Legend.Alignment = Steema.TeeChart.LegendAlignments.Top ChartBar.Aspect.View3D = False ChartBar.Axes.Left.Automatic = True ChartBar.Axes.Left.AutomaticMaximum = True ChartBar.Axes.Left.AutomaticMinimum = True ChartBar.Axes.Left.Labels.ValueFormat = "0.0" ChartBar.Axes.Left.Increment = 0.5 ChartBar.Axes.Left.Labels.LabelHeight(10) 'ChartBar.Axes.Left.Scroll(15, True) 'ChartBar.Axes.Left.Labels.Exponent = True 'Line1.Clear() 'ChartBar.Axes. ChartBar.Axes.Bottom.AutomaticMaximum = False ChartBar.Axes.Bottom.AutomaticMinimum = False ChartBar.Axes.Bottom.Automatic = False ChartBar.Axes.Bottom.Increment = 1 ChartBar.Axes.Bottom.Maximum = stoptime 'ChartBar.Axes.Bottom.Minimum = starttime 'ChartBar.Axes.Bottom.Labels.Width = 20 'ChartBar.Axes.Bottom.Labels.DateTimeFormat = "HH:mm:ss" 'ChartBar.Series(0).XValues.DateTime = False 'ChartBar.Axes.Bottom.MaxXValue = stoptime 'ChartBar.Axes.Bottom.ma = stoptime 'ChartBar.Axes.Bottom.Scroll(1705386785, False) 'ChartBar.Axes.Bottom.Scroll() 'ChartBar.Zoom.ZoomRect(New Rectangle(0, 0, 1000, 1000)) Dim ftemp = tCounta ChartBar.Axes.Left.Maximum = ftemp ' / 100 ChartBar.Axes.Left.Minimum = 0 '/ 100 ChartBar.Axes.Bottom.Labels.Align = -45 ChartBar.Axes.Bottom.Labels.MultiLine = True 'Dim X As Integer = ChartBar 'Dim R As New Rectangle(X, Y, Width, Height) ' ChartBar.Refresh() End Sub Public Sub Testfunction() ChartBar.Header.Text = "" '标题 ChartBar.Header.Visible = True ChartBar.Aspect.View3D = False ChartBar.Axes.Left.Automatic = False ChartBar.Axes.Left.AutomaticMaximum = False ChartBar.Axes.Left.AutomaticMinimum = False ChartBar.Axes.Left.Labels.ValueFormat = "0.0" ChartBar.Axes.Left.Increment = 0.5 ChartBar.Axes.Left.Maximum = 10 ' / 100 ChartBar.Axes.Left.Minimum = 0 '/ 100 ChartBar.Axes.Bottom.AutomaticMaximum = False ChartBar.Axes.Bottom.AutomaticMinimum = False ChartBar.Axes.Bottom.Automatic = False ChartBar.Axes.Bottom.Labels.Align = -45 ChartBar.Axes.Bottom.Labels.MultiLine = True ChartBar.Axes.Bottom.Labels.DateTimeFormat = "yyyy-MM-dd" ChartBar.Series(0).XValues.DateTime = True ' 创建 DateTimeOffset 对象并设置其值为指定的 UTC 秒数 Dim dtOffset As New DateTimeOffset(New DateTime(1970, 1, 1), TimeSpan.Zero) ' 获取本地日期和时间 Dim yt As DateTime = (dtOffset + TimeSpan.FromSeconds(1704822366)).LocalDateTime Dim minValue As DateTime = New DateTime(yt.Year, yt.Month, yt.Day, yt.Hour, yt.Minute, yt.Second) '' 最小日期 yt = (dtOffset + TimeSpan.FromSeconds(1704823530)).LocalDateTime Dim maxValue As DateTime = New DateTime(yt.Year, yt.Month, yt.Day, yt.Hour, yt.Minute, yt.Second) '' 最小日期 ChartBar.Axes.Bottom.Maximum = maxValue.ToOADate ChartBar.Axes.Bottom.Minimum = minValue.ToOADate 'Dim dou As Double = 1 / (maxValue.ToOADate - minValue.ToOADate) 'ChartBar.Axes.Bottom.Increment = TimeSpan.FromSeconds(1).TotalSeconds End Sub Public Sub ksjfk() ' 创建TeeChart控件对象 Dim chart = ChartBar.Chart ' 添加Series到图表上(这里使用Line Series作示例) Dim series As New Steema.TeeChart.Styles.Line() 'chart.Add(series) ChartBar.Series.Add(series) ' 定义要显示的数据点及其相应的X轴标签 Dim xDataPoints() As Double = {10, 20, 30, 40} ' X轴数据点 Dim yDataPoints() As Double = {50, 60, 70, 80} ' Y轴数据点 Dim labels() As String = {"Label1", "Label2", "Label3", "Label4"} ' X轴标签 ' 遍历数据并设置每个数据点的值和标签 For i As Integer = 0 To xDataPoints.Length - 1 Dim point As New PointF(xDataPoints(i), yDataPoints(i)) ' 设置X轴标签 point.X = labels(i) ' 向系列中添加数据点 series.Add(point) Next ' 显示图表 'chart.ShowDialog() End Sub Public Function AddTeeChartStylesLine() As Styles.Line Dim devline As Steema.TeeChart.Styles.Line = New Styles.Line ChartBar.Series.Add(devline) Dim minValue As DateTime = New DateTime(2024, 1, 10, 2, 35, 30) '' 最小日期 Return devline ' Dim chart As TChart = ChartBar End Function Public Sub init_Grid_config() With Grid_config .NewFile() .Cols = 3 .Rows = 3 .DisplayRowNumber = False .Cell(0, 0).Text = "序号" .Cell(0, 1).Text = "属性" .Cell(0, 2).Text = "属性值" .Column(0).Width = 0 .Column(1).Width = 150 .Column(1).Locked = True .Column(2).Width = 200 .Column(1).Alignment = AlignmentEnum.CenterCenter .Column(2).Alignment = AlignmentEnum.CenterCenter .Cell(1, 1).Text = "开始时间" .Cell(2, 1).Text = "结束时间" .Cell(1, 2).CellType = CellTypeEnum.DateTime .Cell(2, 2).CellType = CellTypeEnum.DateTime End With End Sub Public Sub FileTo_Grid_config() If IO.File.Exists(filepath) Then Grid_config.OpenFile(filepath) End If End Sub Public Sub Grid_config_FileTo() Grid_config.SaveFile(filepath) End Sub Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing Grid_config_FileTo() End Sub Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) Handles ToolStripButton1.Click Grid_config.AddItem("") Grid_config.Cell(Grid_config.Rows - 1, 1).Text = "机型" End Sub Private Sub ToolStripButton3_Click(sender As Object, e As EventArgs) Handles ToolStripButton3.Click Grid_configDeleteRow(Grid_config.ActiveCell.Row) End Sub Public Sub Grid_configDeleteRow(erow As Integer) Dim devname As String = Grid_config.Cell(erow, 1).Text If devname.Equals("机型") Then Grid_config.Row(erow).Delete() End If End Sub Private Sub ToolStripButton2_Click(sender As Object, e As EventArgs) Handles ToolStripButton2.Click init_Grid_config() End Sub Private Sub ToolStripButton4_Click(sender As Object, e As EventArgs) Handles ToolStripButton4.Click MysqlDataDispose() End Sub Public Sub MysqlDataDispose() Dim selectstr As String = "SELECT `deviceName`,`eventName`,`timestamp`,`timemills`FROM `mqqtmysql`.`devicestate` WHERE" Dim cstrpar As String = String.Empty Dim starttime, stoptime As DateTime Dim dtZone As DateTime = New DateTime(1970, 1, 1, 0, 0, 0) Try starttime = DateTime.Parse(Grid_config.Cell(1, 2).Text.Trim) stoptime = DateTime.Parse(Grid_config.Cell(2, 2).Text.Trim) If IsNothing(starttime) OrElse IsNothing(stoptime) Then MsgBox($"数据查询失败!!!{vbCrLf }原因:{vbCrLf }日期输入错误") End If Catch ex As Exception MsgBox($"数据查询失败!!!{vbCrLf }原因:{vbCrLf }日期输入错误") End Try For i = 1 To Grid_config.Rows - 1 If i = 1 Then selectstr = $"{selectstr}`timestamp`>='{starttime.Subtract(dtZone).TotalSeconds }' And " ElseIf i = 2 Then selectstr = $"{selectstr}`timestamp`<='{stoptime.Subtract(dtZone).TotalSeconds}' And " Else cstrpar = $"{cstrpar}OR deviceName LIKE '%{Grid_config.Cell(i, 2).Text.Trim}%'{vbCrLf }" End If Next If Not String.IsNullOrEmpty(cstrpar) Then cstrpar = cstrpar.Remove(0, 2) selectstr = $"{selectstr}({cstrpar.Trim }) ORDER BY (`timemills`) DESC" End If Dim rowdic As Dictionary(Of String, Dictionary(Of String, String)) = New Dictionary(Of String, Dictionary(Of String, String)) Dim colounmdic As Dictionary(Of String, String) = New Dictionary(Of String, String) Dim dt As DataTable Try Using db As New DbExecutor(DbExecutor.DbTypeEnum.Mysql, GdbConnString) db.Open() dt = db.ExecuteDataTable(selectstr) If IsNothing(dt) OrElse dt.Rows.Count = 0 OrElse dt.Columns.Count = 0 Then MsgBox($"数据查询失败!!!{vbCrLf }原因:{vbCrLf }数据查询语句异常:{selectstr}") Else rowdic.Add("colounmdic", colounmdic) For i = 0 To dt.Rows.Count - 1 Dim rownodedic As Dictionary(Of String, String) = New Dictionary(Of String, String) Dim celltext As String = String.Empty If dt(i)(1).ToString.Trim.Equals("EV_ONLINE") Then celltext = 1 ElseIf dt(i)(1).ToString.Trim.Equals("EV_OFFLINE") Then celltext = 0 End If If Not colounmdic.ContainsKey(dt(i)(0).ToString.Trim) Then colounmdic.Add(dt(i)(0).ToString.Trim, i) End If rownodedic.Add(dt(i)(0).ToString.Trim, celltext) If rowdic.ContainsKey(dt(i)(3).ToString.Trim) Then ' Else rowdic.Add(dt(i)(3).ToString.Trim, rownodedic) Console.WriteLine($"重复字段:{dt(i)(3).ToString.Trim}") End If Next End If End Using initGrid_Mysqldate(rowdic) Catch ex As Exception MsgBox($"数据查询失败!!!{vbCrLf }原因:{vbCrLf }{ex.Message }") Return End Try End Sub Public Sub initGrid_Mysqldate(rowdic As Dictionary(Of String, Dictionary(Of String, String))) If IsNothing(rowdic) AndAlso rowdic.Count = 0 AndAlso (Not rowdic.ContainsKey("colounmdic")) Then MsgBox($"数据加载失败!!数据为空或未检测到列信息。") End If Dim starttime As Long = 0 Dim stoptime As Long = 0 Dim kkdic As Dictionary(Of String, Dictionary(Of Long, Double)) = New Dictionary(Of String, Dictionary(Of Long, Double)) Dim colounmdic As Dictionary(Of String, String) = rowdic.Item("colounmdic") With Grid_Mysqldate .NewFile() .AutoRedraw = False .Cols = colounmdic.Count + 3 .Rows = 1 .DisplayRowNumber = True .Cell(0, 0).Text = "序号" .Cell(0, 1).Text = "时间" .Cell(0, 2).Text = "时间戳" .Column(0).Width = 20 .Column(1).Width = 150 .Column(1).Alignment = AlignmentEnum.CenterCenter For i = 0 To colounmdic.Count - 1 .Cell(0, i + 3).Text = colounmdic.Keys(i) .Column(i + 3).Alignment = AlignmentEnum.CenterCenter Next Dim dtOffset As New DateTimeOffset(New DateTime(1970, 1, 1), TimeSpan.Zero) ' 获取本地日期和时间 For Each node In rowdic If node.Key.Equals("colounmdic") Then Continue For .AddItem("") Dim t As Long = Long.Parse(node.Key) t = t / 1000 Dim yt As DateTime = (dtOffset + TimeSpan.FromSeconds(t)).LocalDateTime If starttime = 0 OrElse t < starttime Then starttime = t End If If stoptime = 0 OrElse t > stoptime Then stoptime = t End If .Cell(.Rows - 1, 1).Text = yt.ToString("yyyy-MM-dd HH:mm:ss") .Cell(.Rows - 1, 2).Text = t.ToString For Each index In node.Value For j = 0 To colounmdic.Count - 1 ' 'Console.WriteLine(.Cell(0, j + 2).Text) If .Cell(0, j + 3).Text.Equals(index.Key) Then .Cell(.Rows - 1, j + 3).Text = index.Value End If Next Next Dim datadic As Dictionary(Of Long, Double) If kkdic.ContainsKey(node.Value.Keys(0)) Then datadic = kkdic.Item(node.Value.Keys(0)) If datadic.ContainsKey(t) Then datadic.Item(t) = CInt(node.Value.Values(0)) Else datadic.Add(t, node.Value.Values(0)) End If Else datadic = New Dictionary(Of Long, Double) datadic.Add(t, node.Value.Values(0)) kkdic.Add(node.Value.Keys(0), datadic) End If Next End With Grid_Mysqldate.AutoRedraw = True Grid_Mysqldate.Refresh() InitPieChart(kkdic, starttime, stoptime) End Sub ''' ''' 初始化Chart控件 ''' Private Sub InitTeeChart(kkdic As Dictionary(Of String, Dictionary(Of Long, Double)), starttime As Long, stoptime As Long) ChartBar.AutoRepaint = False ChartBar.Header.Lines = New String() {""} 'TeeChart标题 ChartBar.Panning.InsideBounds = True ChartBar.Panning.Allow = ScrollModes.Horizontal InitCustomAxies(kkdic, starttime, stoptime) InitFastLine(kkdic) InitCursor() ChartBar.AutoRepaint = True ChartBar.Refresh() End Sub ''' ''' 初始化轴 ''' Private Sub InitCustomAxies(kkdic As Dictionary(Of String, Dictionary(Of Long, Double)), starttime As Long, stoptime As Long) _axis.Clear() ChartBar.Axes.Custom.Clear() ChartBar.Walls.Visible = False '不显示立面(背景色将统一) ChartBar.Axes.Bottom.Title.Caption = "时间轴" ChartBar.Axes.Bottom.Title.Visible = False ChartBar.Axes.Bottom.MaximumOffset = 4 '最大值偏移 ChartBar.Axes.Bottom.MinimumOffset = 4 '最小值偏移 ChartBar.Axes.Bottom.Grid.Style = System.Drawing.Drawing2D.DashStyle.Dash ChartBar.Axes.Bottom.Grid.Width = 2 ChartBar.Axes.Bottom.Ticks.Color = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(255, Byte), Integer), CType(CType(255, Byte), Integer)) ChartBar.Axes.Bottom.Ticks.Length = 4 '标记长度 ChartBar.Axes.Bottom.Ticks.Width = 4 '标记宽度 ChartBar.Axes.Bottom.Grid.Transparency = 60 ' _axis.Add(ChartBar.Axes.Bottom) ChartBar.Axes.Bottom.Automatic = False Dim dtOffset As New DateTimeOffset(New DateTime(1970, 1, 1, 0, 0, 0)) ' 获取本地日期和时间 Dim yt As DateTime yt = (dtOffset.AddSeconds(stoptime)).LocalDateTime ChartBar.Axes.Bottom.Maximum = yt.ToOADate Dim bvtOffset As New DateTimeOffset(New DateTime(1970, 1, 1, 0, 0, 0)) yt = (dtOffset.AddSeconds(starttime )).LocalDateTime ChartBar.Axes.Bottom.Minimum = yt.ToOADate ' ChartBar.Axes.Bottom.Increment = 1 ChartBar.Axes.Bottom.Logarithmic = False 'ChartBar.Axes.Right.Title.Right = 20 ChartBar.Axes.Bottom.Labels.DateTimeFormat = "yyyy-MM-dd HH" ChartBar.Axes.Left.Title.Caption = "电流-电压轴" ChartBar.Axes.Left.Title.Visible = False ChartBar.Axes.Left.MaximumOffset = 4 '最大值偏移 ChartBar.Axes.Left.MinimumOffset = 4 '最小值偏移 ChartBar.Axes.Left.Grid.Style = System.Drawing.Drawing2D.DashStyle.Dash ChartBar.Axes.Left.Grid.Width = 2 ChartBar.Axes.Left.Ticks.Color = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(255, Byte), Integer), CType(CType(255, Byte), Integer)) ChartBar.Axes.Left.Ticks.Length = 2 '标记长度 ChartBar.Axes.Left.Ticks.Width = 2 '标记宽度 ChartBar.Axes.Left.Grid.Transparency = 60 ChartBar.Axes.Left.Automatic = False ChartBar.Axes.Left.Minimum = 0.001 ChartBar.Axes.Left.Maximum = 1000 ChartBar.Axes.Left.Logarithmic = True For i = 0 To kkdic.Count - 1 '_axis.Add(ChartBar.Axes.Left) 'Case Else 'IO Dim idx As Integer = i _axis.Add(New Steema.TeeChart.Axis) _axis(i).Title.Caption = kkdic.Keys(i) '标题文本 _axis(i).Title.Font.Brush.Color = Color.GhostWhite _axis(i).Title.Angle = 0 '标题角度 _axis(i).AxisPen.Color = Color.FromArgb(255, idx * 12, 255 - idx * 10, idx * 6) '颜色 _axis(i).OtherSide = True '右边显示 _axis(i).StartPosition = idx * 8.0R _axis(i).EndPosition = _axis(i).StartPosition + 4.0R _axis(i).Automatic = False _axis(i).Minimum = 0 _axis(i).Maximum = 1 _axis(i).Increment = 1.0R _axis(i).Grid.Visible = False _axis(i).Labels.Angle = 0 '角度 ChartBar.Axes.Custom.Add(_axis(i)) 'End Select Next End Sub ''' ''' 初始化线 ''' Private Sub InitFastLine(kkdic As Dictionary(Of String, Dictionary(Of Long, Double))) ChartBar.Series.Clear() _fastLine.Clear() For i = 0 To kkdic.Count - 1 _fastLine.Add(kkdic.Keys(i), New Steema.TeeChart.Styles.FastLine) AddHandler _fastLine.Item(kkdic.Keys(i)).Click, AddressOf FastLine1_Click ' _fastLine(i).Title = $"电流{i}" ' FastLineTitle(i) '标题 _fastLine.Item(kkdic.Keys(i)).TreatNulls = Steema.TeeChart.Styles.TreatNullsStyle.DoNotPaint ChartBar.Series.Add(_fastLine.Item(kkdic.Keys(i))) _fastLine.Item(kkdic.Keys(i)).XValues.DateTime = True 'Select Case i ' Case 0 ' _fastLine(i).Title = $"电流" ' ' FastLine(i).CustomVertAxis = ChartBar.Axes.Left '绑定电流轴 ' _fastLine(i).Transparency = 0 '线条透明度 ' _fastLine(i).LinePen.Color = Color.FromArgb(255, 255, 0, 0) '线条颜色 ' ' Case 1 To 5 ' If i = 1 Then ' _fastLine(i).Title = $"电压" ' Else ' _fastLine(i).Title = $"CH{i - 1}" ' End If ' ' _fastLine(i).Visible = False ' ' _fastLine(i).CustomVertAxis = _axis(0) '绑定电压 ' _fastLine(i).Transparency = 75 '线条透明度 ' _fastLine(i).LinePen.Color = Color.FromArgb(126, 0, 0, 255) '线条颜色 ' _fastLine(i).Legend.Visible = True '不在图例中显示 ' Case Else _fastLine.Item(kkdic.Keys(i)).Title = $"{kkdic.Keys(i)}" '_fastLine(i).Legend.Visible = True '不在图例中显示 ' _fastLine.Item(kkdic.Keys(i)).Visible = False _fastLine.Item(kkdic.Keys(i)).Transparency = 0 '线条透明度 _fastLine.Item(kkdic.Keys(i)).CustomVertAxis = _axis(i) '绑定IO轴 _fastLine.Item(kkdic.Keys(i)).Stairs = True '线条阶梯状 Dim random As New Random() _fastLine.Item(kkdic.Keys(i)).LinePen.Color = Color.GhostWhite '线条颜色 '_fastLine.Item(kkdic.Keys(i)).LinePen.Color = Color.Blue _fastLine.Item(kkdic.Keys(i)).LinePen.Width = 2 _fastLine.Item(kkdic.Keys(i)).Legend.Visible = False '不在图例中显示 ' _fastLine(i).LinePen.Color = _axis(i - 5).Labels.Color 'End Select ' FastLine(i).LinePen.Color = Color.FromArgb(12, 12, 12, 12) '颜色 ' FastLine(i).ColorEach = False '各点之间颜色不一 Next End Sub Private Sub InitCursor() ChartBar.Tools.Clear() For i = 0 To _curSor.Length - 1 _curSor(i) = New Steema.TeeChart.Tools.CursorTool ChartBar.Tools.Add(_curSor(i)) _curSor(i).Style = Steema.TeeChart.Tools.CursorToolStyles.Vertical _curSor(i).OriginalCursor = System.Windows.Forms.Cursors.Default _curSor(i).Pen.Style = System.Drawing.Drawing2D.DashStyle.Dot _curSor(i).Pen.Width = 2 _curSor(i).Tag = i _curSor(i).Active = True _curSor(i).FollowMouse = False AddHandler _curSor(i).Change, AddressOf CursorChange Select Case i Case 0 _curSor(i).Pen.Color = System.Drawing.Color.Orange Case 1 _curSor(i).Pen.Color = System.Drawing.Color.Lime Case 2 _curSor(i).Pen.Color = System.Drawing.Color.FromArgb(CType(CType(255, Byte), Integer), CType(CType(128, Byte), Integer), CType(CType(255, Byte), Integer)) End Select Next End Sub ''' ''' 光标位置改变触发事件 ''' ''' ''' Private Sub CursorChange(sender As Object, e As Steema.TeeChart.Tools.CursorChangeEventArgs) Dim index As Integer = sender.tag CursorChangeDataDisplay(index) End Sub ''' ''' 光标移动显示数据 ''' ''' 当前移动的是第几个光标 Private Sub CursorChangeDataDisplay(index As Integer) Dim X1 As Double = 0 Dim X2 As Double = 0 Dim dtOffset As New DateTimeOffset(New DateTime(1900, 1, 1), TimeSpan.Zero) ' 获取本地日期和时间 Dim yt As DateTime Dim ts As TimeSpan Select Case index Case 0 X1 = _curSor(index).XValue.ToString("#0.0000") 'yt.too yt = DateTime.FromOADate(X1) 'Console.WriteLine($"CursorChangeDataDisplay:X1 {X1}:{yt.ToString("yyyy-MM-dd HH:mm:ss")}") 'yt = (dtOffset + TimeSpan.FromDays(X1)).LocalDateTime yt = yt + TimeSpan.FromHours(8) labY1.Text = yt.ToString("yyyy-MM-dd HH:mm:ss") ts = New TimeSpan(yt.Ticks) labY1.Tag = ts.TotalSeconds Case 1 X2 = _curSor(index).XValue.ToString("#0.0000") yt = DateTime.FromOADate(X2) yt = yt + TimeSpan.FromHours(8) labY2.Text = yt.ToString("yyyy-MM-dd HH:mm:ss") 'Console.WriteLine($"CursorChangeDataDisplay:X2 {X2}:{yt.ToString("yyyy-MM-dd HH:mm:ss")}") ts = New TimeSpan(yt.Ticks) labY2.Tag = ts.TotalSeconds End Select Double.TryParse(labY1.Tag, X1) Double.TryParse(labY2.Tag, X2) Dim couinm As Double = X2 - X1 lab1_2.Text = "" If couinm < 0 Then lab1_2.Text = " - " End If ';'Console.WriteLine($"CursorChangeDataDisplay:{ _curSor(index).XValue.ToString("#0.00")}|{_curSor(index).XValue.ToString("#0.00")}|{couinm}") Dim timeval As TimeSpan = TimeSpan.FromSeconds(Math.Abs(couinm)) ' 'Console.WriteLine(couinm) If timeval.Days > 0 Then lab1_2.Text = $"{ lab1_2.Text}{timeval.Days }天 " End If lab1_2.Text = $"{ lab1_2.Text}{timeval.Hours }:{timeval.Minutes }:{timeval.Seconds }" End Sub Private _curTool As Steema.TeeChart.Tools.CursorTool Private Sub ChartBar_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles ChartBar.MouseDoubleClick If e.Button = MouseButtons.Middle Then ChartBar.Zoom.Undo() ElseIf e.Button = MouseButtons.Left Then Dim idx As Integer Dim row As Integer If _curTool Is Nothing Then idx = 0 _curTool = _curSor(idx) _curTool.FollowMouse = True 'row = _rowChart.Cursor + idx * (EnCursor.Width + 2) + 1 + EnCursor.FollowMouse + 1 'GrdChartInfo.Cell(row, EnGridCol.Value).Text = $"1" Else If _curTool.FollowMouse = False Then idx = _curTool.Tag ' row = _rowChart.Cursor + idx * (EnCursor.Width + 2) + 1 + EnCursor.FollowMouse + 1 '_isUserChange = False _curTool.FollowMouse = False 'GrdChartInfo.Cell(row, EnGridCol.Value).Text = $"0" idx += 1 If idx >= _curSor.Length Then idx = 0 _curTool = _curSor(idx) _curTool.FollowMouse = True Else _curTool = _curSor(idx) _curTool.FollowMouse = True ' row = _rowChart.Cursor + idx * (EnCursor.Width + 2) + 1 + EnCursor.FollowMouse + 1 'GrdChartInfo.Cell(row, EnGridCol.Value).Text = $"1" End If '_isUserChange = True End If End If End If End Sub Private Sub ChartBar_MouseClick(sender As Object, e As MouseEventArgs) Handles ChartBar.MouseClick If e.Button = MouseButtons.Middle Then ChartBar.Zoom.Undo() ElseIf e.Button = MouseButtons.Right Then If IsNothing(_curTool) Then Return _curTool.FollowMouse = False End If End Sub Private Sub FastLine1_Click(sender As Object, e As MouseEventArgs) Dim fl As Styles.FastLine = sender For Each node In _fastLine If node.Value.Title.Equals(fl.Title) Then fl = node.Value Dim x1 As Double = 0 labdevanme.Text = fl.Title ''Console.WriteLine($"{e.X} {fl.YValues.Value(e.X).ToString("#0.0.")} {e.Y} {fl.YValues.Value(e.Y).ToString("#0.00")}") Dim intcv As Integer = CInt(Math.Round(ChartBar.Series(0).YScreenToValue(e.Y))) labval.Text = intcv.ToString 'Console.WriteLine(fl.XValues.Value.Length) x1 = ChartBar.Series(0).XScreenToValue(e.X) Dim stra As String = fl.XValues.AsDateTime(e.X) Dim dtOffset As New DateTimeOffset(New DateTime(1970, 1, 1), TimeSpan.Zero) ' 获取本地日期和时间 Dim yt As DateTime yt = DateTime.FromOADate(x1) yt = yt + TimeSpan.FromHours(8) 'Console.WriteLine($"FastLine1_Click:{x1}:{ yt.ToString("yyyy-MM-dd HH:mm:ss")}") labDate.Text = yt.ToString("yyyy-MM-dd HH:mm:ss") End If Next End Sub End Class