-
Notifications
You must be signed in to change notification settings - Fork 4
/
Form1.vb
67 lines (53 loc) · 2.19 KB
/
Form1.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...
Namespace ASwiftPlotChart
Public Partial Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Const interval As Integer = 20
Private random As Random = New Random()
Private TimeInterval As Integer = 10
Private value1 As Double = 10.0
Private ReadOnly Property AxisXRange As Range
Get
Dim diagram As SwiftPlotDiagram = TryCast(chartControl1.Diagram, SwiftPlotDiagram)
If diagram IsNot Nothing Then Return diagram.AxisX.VisualRange
Return Nothing
End Get
End Property
Private Function CalculateNextValue(ByVal value As Double) As Double
Return value + (random.NextDouble() * 10.0 - 5.0)
End Function
Private Sub UpdateValues()
value1 = CalculateNextValue(value1)
End Sub
Private Sub timer1_Tick(ByVal sender As Object, ByVal e As EventArgs)
Dim series1 As Series = chartControl1.Series(0)
If series1 Is Nothing Then Return
Dim argument As Date = Date.Now
Dim pointsToUpdate1 As SeriesPoint() = New SeriesPoint(19) {}
For i As Integer = 0 To interval - 1
pointsToUpdate1(i) = New SeriesPoint(argument, value1)
argument = argument.AddMilliseconds(1)
UpdateValues()
Next
Dim minDate As Date = argument.AddSeconds(-TimeInterval)
Dim pointsToRemoveCount As Integer = 0
For Each point As SeriesPoint In series1.Points
If point.DateTimeArgument < minDate Then pointsToRemoveCount += 1
Next
If pointsToRemoveCount < series1.Points.Count Then pointsToRemoveCount -= 1
series1.Points.AddRange(pointsToUpdate1)
If pointsToRemoveCount > 0 Then
series1.Points.RemoveRange(0, pointsToRemoveCount)
End If
If AxisXRange IsNot Nothing Then
AxisXRange.SetMinMaxValues(minDate, argument)
End If
End Sub
End Class
End Namespace