-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormDesigner.cs
53 lines (49 loc) · 1.92 KB
/
FormDesigner.cs
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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using DevExpress.DashboardCommon;
using DevExpress.DashboardCommon.ViewerData;
namespace WinForm {
public partial class FormDesigner : Form {
public FormDesigner() {
try {
IndicatorFactory.Register<MovingIndicator>("Moving average");
} catch(Exception e) {
MessageBox.Show(e.Message);
}
InitializeComponent();
var dashboard = new Dashboard1();
ChartDashboardItem chartItem = dashboard.Items.First(x => x.ComponentName == "chartDashboardItem1") as ChartDashboardItem;
MovingIndicator trendLine = new MovingIndicator() {
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();
}
}
public class MovingIndicator : ChartCustomIndicator {
protected override Dictionary<AxisPoint, object> Calculate(Dictionary<AxisPoint, decimal?> values) {
var items = new Dictionary<AxisPoint, object>(values.Count);
var sum = decimal.Zero;
var count = 0;
foreach(KeyValuePair<AxisPoint, decimal?> point in values) {
if(count == 0) {
items.Add(point.Key, null);
} else {
items.Add(point.Key, sum / count);
}
sum += point.Value ?? 0;
count++;
}
return items;
}
}
}