forked from syncfusion/xamarin-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GettingStartedRangeNavigator.cs
123 lines (105 loc) · 3.88 KB
/
GettingStartedRangeNavigator.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#region Copyright Syncfusion Inc. 2001 - 2019
// Copyright Syncfusion Inc. 2001 - 2019. All rights reserved.
// Use of this code is subject to the terms of our license.
// A copy of the current license can be obtained at any time by e-mailing
// [email protected]. Any infringement will be prosecuted under
// applicable laws.
#endregion
using System;
using Syncfusion.SfChart.iOS;
#if __UNIFIED__
using Foundation;
using UIKit;
using CoreGraphics;
#else
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.CoreGraphics;
using nint = System.Int32;
using nuint = System.Int32;
using CGRect = System.Drawing.RectangleF;
#endif
namespace SampleBrowser
{
public class GettingStartedRangeNavigator : SampleView
{
SFChart chart;
SFDateTimeRangeNavigator rangeNavigator;
SFDateTimeAxis primaryAxis;
SFNumericalAxis secondaryAxis;
ChartViewModel dataModel = new ChartViewModel();
public GettingStartedRangeNavigator ()
{
chart = new SFChart ();
primaryAxis = new SFDateTimeAxis ();
primaryAxis.Minimum = DateTimeToNSDate( new DateTime (2015, 5, 15, 0, 0, 0));
primaryAxis.Maximum = DateTimeToNSDate( new DateTime (2015, 8, 15, 0, 0, 0));
chart.PrimaryAxis = primaryAxis;
secondaryAxis = new SFNumericalAxis ();
chart.SecondaryAxis = secondaryAxis;
SFSplineAreaSeries series = new SFSplineAreaSeries();
series.Alpha = 0.6f;
series.BorderColor = UIColor.FromRGBA(255.0f / 255.0f, 191.0f / 255.0f, 0.0f / 255.0f, 1.0f);
series.ItemsSource = dataModel.DateTimeRangeData;
series.XBindingPath = "XValue";
series.YBindingPath = "YValue";
chart.Series.Add(series);
this.AddSubview (chart);
rangeNavigator = new SFDateTimeRangeNavigator ();
rangeNavigator.Delegate = new RangeNavigatorDelegate(primaryAxis);
SFSplineAreaSeries series1 = new SFSplineAreaSeries();
series1.Alpha = 0.6f;
series1.BorderColor = UIColor.FromRGBA(255.0f / 255.0f, 191.0f / 255.0f, 0.0f / 255.0f, 1.0f);
series1.ItemsSource = dataModel.DateTimeRangeData;
series1.XBindingPath = "XValue";
series1.YBindingPath = "YValue";
((SFChart)rangeNavigator.Content).Series.Add(series1);
DateTime minDate = new DateTime (2015, 1, 1, 0, 0, 0);
DateTime maxDate = new DateTime (2015, 12, 1, 0, 0, 0);
DateTime startDate = new DateTime (2015, 5, 15, 0, 0, 0);
DateTime endDate = new DateTime (2015, 8, 15, 0, 0, 0);
rangeNavigator.Minimum = DateTimeToNSDate (minDate);
rangeNavigator.Maximum = DateTimeToNSDate (maxDate);
rangeNavigator.ViewRangeStart = DateTimeToNSDate (startDate);
rangeNavigator.ViewRangeEnd = DateTimeToNSDate (endDate);
this.AddSubview (rangeNavigator);
//this.control = this;
}
public override void LayoutSubviews ()
{
foreach (var view in this.Subviews) {
if (view == rangeNavigator)
view.Frame = new CGRect (0, Frame.Size.Height - 100, Frame.Width, 100);
else if (view == chart)
view.Frame = new CGRect (0, 0, Frame.Size.Width, Frame.Size.Height - 100);
else
view.Frame = Frame;
}
base.LayoutSubviews ();
}
public void UpdateChart(NSDate startDate, NSDate endDate)
{
primaryAxis.Minimum = startDate;
primaryAxis.Maximum = endDate;
}
public NSDate DateTimeToNSDate(DateTime date)
{
DateTime reference = TimeZone.CurrentTimeZone.ToLocalTime(
new DateTime(2001, 1, 1, 0, 0, 0) );
return NSDate.FromTimeIntervalSinceReferenceDate((date - reference).TotalSeconds);
}
}
}
public class RangeNavigatorDelegate: SFRangeNavigatorDelegate
{
SFDateTimeAxis primaryAxis;
public RangeNavigatorDelegate(SFDateTimeAxis _primaryAxis)
{
primaryAxis = _primaryAxis;
}
public override void RangeChanged (SFDateTimeRangeNavigator rangeNavigator, NSDate startDate, NSDate endDate)
{
primaryAxis.Minimum = startDate;
primaryAxis.Maximum = endDate;
}
}