This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.vb
76 lines (65 loc) · 2.24 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
68
69
70
71
72
73
74
75
76
Imports DevExpress.XtraCharts
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Forms
Namespace DataAggregation
Partial Public Class Form1
Inherits DevExpress.XtraEditors.XtraForm
Public Sub New()
InitializeComponent()
End Sub
Private Function GenerateData(ByVal pointCount As Integer) As List(Of DataPoint)
Dim result As New List(Of DataPoint)(pointCount)
Dim value As Double = 0
Dim argument As DateTime = DateTime.Now.AddHours(-pointCount)
Dim random As New Random()
For i As Double = 0 To pointCount - 1
result.Add(New DataPoint With {
.Argument = argument.AddHours(i),
.Value = Math.Abs(value)
})
value += (random.NextDouble() * 10.0 - 5.0)
Next i
Return result
End Function
#Region "#CustomAggregateFunction"
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim series As Series = chartControl.Series("Random Data")
series.DataSource = GenerateData(100_000)
series.ArgumentDataMember = "Argument"
series.ValueDataMembers.AddRange("Value", "Value", "Value", "Value")
Dim diagram As XYDiagram = TryCast(chartControl.Diagram, XYDiagram)
diagram.AxisX.DateTimeScaleOptions.AggregateFunction = AggregateFunction.Custom
diagram.AxisX.DateTimeScaleOptions.CustomAggregateFunction = New OhlcAggregateFunction()
End Sub
Private Class OhlcAggregateFunction
Inherits CustomAggregateFunction
Public Overrides Function Calculate(ByVal groupInfo As GroupInfo) As Double()
Dim open As Double = groupInfo.Values1.First()
Dim close As Double = groupInfo.Values1.Last()
Dim high As Double = Double.MinValue
Dim low As Double = Double.MaxValue
For Each value As Double In groupInfo.Values1
If high < value Then
high = value
End If
If low > value Then
low = value
End If
Next value
Return New Double() { high, low, open, close }
End Function
End Class
#End Region ' #CustomAggregateFunction
Private Class DataPoint
Public Property Argument() As DateTime
Public Property Value() As Double
End Class
End Class
End Namespace