-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDefault.aspx.cs
76 lines (59 loc) · 3.41 KB
/
Default.aspx.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.XtraCharts;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Cpecify ScaleTypes
WebChartControl1.Series[0].ArgumentScaleType = ScaleType.Qualitative;
WebChartControl1.Series[0].ValueScaleType = ScaleType.DateTime;
WebChartControl1.Series[1].ArgumentScaleType = ScaleType.Qualitative;
WebChartControl1.Series[1].ValueScaleType = ScaleType.DateTime;
(WebChartControl1.Series[1].Label as RangeBarSeriesLabel).Position = RangeBarLabelPosition.Inside;
// Bound series to data
WebChartControl1.DataSource = GanttData.CreateData();
WebChartControl1.Series[0].ArgumentDataMember = "GanntTask";
WebChartControl1.Series[0].ValueDataMembers.AddRange(new string[] { "GanntStart", "GanntEnd" });
// Create argument descriptions for the summary function.
SummaryFunctionArgumentDescription argument1Description =
new SummaryFunctionArgumentDescription("GanntStart", ScaleType.DateTime);
SummaryFunctionArgumentDescription argument2Description =
new SummaryFunctionArgumentDescription("GanntEnd", ScaleType.DateTime);
SummaryFunctionArgumentDescription argument3Description =
new SummaryFunctionArgumentDescription("GanttPercentageComplete", ScaleType.Numerical);
// Register the summary function in a chart.
WebChartControl1.RegisterSummaryFunction("CalcPercentageComplete", "CalcPercentageComplete", 2,
new SummaryFunctionArgumentDescription[] { argument1Description, argument2Description, argument3Description},
CalcPercentageComplete);
WebChartControl1.Series[1].ArgumentDataMember = "GanntTask";
WebChartControl1.Series[1].SummaryFunction = "CalcPercentageComplete([GanntStart], [GanntEnd], [GanttPercentageComplete])";
// Don't forget this !:)
WebChartControl1.DataBind();
}
// Declare the summary function.
private static SeriesPoint[] CalcPercentageComplete(Series series, object argument,
string[] functionArguments, DataSourceValues[] values, object[] colors) {
// Create an array of the resulting series points.
SeriesPoint[] points = new SeriesPoint[1] { new SeriesPoint(argument.ToString(), new DateTime[] { new DateTime(), new DateTime() }) };
// Calculate values
DateTime start = Convert.ToDateTime(values[0][functionArguments[0]]);
DateTime end = Convert.ToDateTime(values[0][functionArguments[1]]);
double ganttPercentageComplete = Convert.ToDouble(values[0][functionArguments[2]]);
TimeSpan ts = end - start;
points[0].DateTimeValues[0] = start;
points[0].DateTimeValues[1] = start + TimeSpan.FromHours(ts.TotalHours * ganttPercentageComplete/100);
object ob = values[0][""];
points[0].Tag = (ob as DataRowView).Row["GanttOwner"].ToString() + "|" + ganttPercentageComplete.ToString();
return points;
}
protected void WebChartControl1_CustomDrawSeriesPoint(object sender, CustomDrawSeriesPointEventArgs e) {
if(e.Series.Name == "Actual") {
e.LabelText = e.SeriesPoint.Tag.ToString().Split('|')[0];
e.SecondLabelText = e.SeriesPoint.Tag.ToString().Split('|')[1] + "%";
}
}
}