-
Notifications
You must be signed in to change notification settings - Fork 0
/
FormDesigner.vb
57 lines (51 loc) · 1.67 KB
/
FormDesigner.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
Imports System
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Linq
Imports System.Windows.Forms
Imports DevExpress.DashboardCommon
Imports DevExpress.DashboardCommon.ViewerData
Namespace WinForm
Partial Public Class FormDesigner
Inherits Form
Public Sub New()
Try
IndicatorFactory.Register(Of MovingIndicator)("Moving average")
Catch e As Exception
MessageBox.Show(e.Message)
End Try
InitializeComponent()
Dim dashboard = New Dashboard1()
Dim chartItem As ChartDashboardItem = TryCast(dashboard.Items.First(Function(x) x.ComponentName = "chartDashboardItem1"), ChartDashboardItem)
Dim trendLine As New MovingIndicator() With {
.Name = "MovingLine1",
.Value = "DataItem1",
.ValueLevel = DevExpress.XtraCharts.ValueLevel.Value,
.Color = Color.Orange,
.LegendText = "Moving Average"
}
chartItem.Indicators.Add(trendLine)
dashboardDesigner.Dashboard = dashboard
dashboardDesigner.CreateRibbon()
dashboardDesigner.CreateCustomItemBars()
End Sub
End Class
Public Class MovingIndicator
Inherits ChartCustomIndicator
Protected Overrides Function Calculate(ByVal values As Dictionary(Of AxisPoint, Decimal?)) As Dictionary(Of AxisPoint, Object)
Dim items = New Dictionary(Of AxisPoint, Object)(values.Count)
Dim sum = Decimal.Zero
Dim count = 0
For Each point As KeyValuePair(Of AxisPoint, Decimal?) In values
If count = 0 Then
items.Add(point.Key, Nothing)
Else
items.Add(point.Key, sum / count)
End If
sum += If(point.Value, 0)
count += 1
Next point
Return items
End Function
End Class
End Namespace