-
Notifications
You must be signed in to change notification settings - Fork 201
/
Copy pathDataPointSelection.cs
214 lines (181 loc) · 7.37 KB
/
DataPointSelection.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#region Copyright Syncfusion Inc. 2001 - 2016
// Copyright Syncfusion Inc. 2001 - 2016. 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;
using System.Collections.Generic;
using System.Collections.ObjectModel;
#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 CGSize = System.Drawing.SizeF;
using CGRect = System.Drawing.RectangleF;
#endif
namespace SampleBrowser
{
public class DataPointSelection : SampleView
{
SFChart chart;
ChartViewModel dataModel;
UIPickerView selectionPicker;
UIButton doneButton;
UIButton selectionTypeTextButton;
public DataPointSelection()
{
selectionPicker = new UIPickerView();
doneButton = new UIButton();
selectionTypeTextButton = new UIButton();
chart = new SFChart();
chart.Title.Text = new NSString("Product Sale 2016");
SFCategoryAxis primary = new SFCategoryAxis();
primary.LabelPlacement = SFChartLabelPlacement.BetweenTicks;
primary.Title.Text = new NSString("Month");
chart.PrimaryAxis = primary;
chart.SecondaryAxis = new SFNumericalAxis() { ShowMajorGridLines = false };
chart.SecondaryAxis.Title.Text = new NSString("Sales");
dataModel = new ChartViewModel();
SFColumnSeries series = new SFColumnSeries();
series.ItemsSource = dataModel.SelectionData;
series.XBindingPath = "XValue";
series.YBindingPath = "YValue";
series.EnableDataPointSelection = true;
series.EnableAnimation = true;
series.Color = UIColor.FromRGBA(0, 189f / 255f, 174f / 255f, 1f);
series.SelectedDataPointColor = UIColor.FromRGBA(0, 113f / 255f, 104f / 255f, 1f);
chart.Series.Add(series);
SFColumnSeries series1 = new SFColumnSeries();
series1.ItemsSource = dataModel.SelectionData1;
series1.XBindingPath = "XValue";
series1.YBindingPath = "YValue";
series1.EnableDataPointSelection = true;
series1.EnableAnimation = true;
series1.Color = UIColor.FromRGBA(0, 132f / 255f, 232f / 255f, 1f);
series1.SelectedDataPointColor = UIColor.FromRGBA(0, 79f / 255f, 178f / 255f, 1f);
chart.Series.Add(series1);
chart.AddChartBehavior(new SFChartSelectionBehavior());
this.AddSubview(chart);
selectionTypeTextButton.SetTitle(" Data Point Selection", UIControlState.Normal);
selectionTypeTextButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Center;
selectionTypeTextButton.SetTitleColor(UIColor.Black, UIControlState.Normal);
selectionTypeTextButton.TouchUpInside += delegate
{
selectionPicker.Hidden = false;
doneButton.Hidden = false;
this.BecomeFirstResponder();
};
selectionTypeTextButton.BackgroundColor = UIColor.Clear;
selectionTypeTextButton.Layer.BorderWidth = 2.0f;
selectionTypeTextButton.Layer.BorderColor = UIColor.FromRGB(240.0f / 255.0f, 240.0f / 255.0f, 240.0f / 255.0f).CGColor;
selectionTypeTextButton.Layer.CornerRadius = 8.0f;
this.AddSubview(selectionTypeTextButton);
selectionPicker.ShowSelectionIndicator = true;
selectionPicker.Hidden = true;
selectionPicker.Model = new PickerViewModel(chart, selectionTypeTextButton);
selectionPicker.BackgroundColor = UIColor.FromRGB(240f / 255.0f, 240f / 255.0f, 240f / 255.0f);
selectionPicker.SelectedRowInComponent(0);
this.AddSubview(selectionPicker);
doneButton.SetTitle("Done" + "\t", UIControlState.Normal);
doneButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Right;
doneButton.SetTitleColor(UIColor.Black, UIControlState.Normal);
doneButton.TouchUpInside += delegate
{
selectionPicker.Hidden = true;
doneButton.Hidden = true;
this.BecomeFirstResponder();
};
doneButton.BackgroundColor = UIColor.FromRGB(240f / 255.0f, 240f / 255.0f, 240f / 255.0f);
doneButton.Hidden = true;
this.AddSubview(doneButton);
}
public override void LayoutSubviews()
{
foreach (var view in this.Subviews)
{
if (view == chart)
{
chart.Frame = new CGRect(this.Bounds.X, this.Bounds.Y + 40,
this.Bounds.Width, this.Bounds.Height - 40);
}
else if (view == selectionTypeTextButton)
{
selectionTypeTextButton.Frame = new CGRect(10, Bounds.Y, Frame.Size.Width - 20, 32);
}
else if (view == doneButton)
{
if (Utility.IsIPad)
{
doneButton.Frame = new CGRect(0, Bounds.Y + Frame.Size.Height - 253, Frame.Size.Width, 35);
}
else
{
doneButton.Frame = new CGRect(0, Bounds.Y + Frame.Size.Height - 143, Frame.Size.Width, 35);
}
}
else if (view == selectionPicker)
{
if (Utility.IsIPad)
{
selectionPicker.Frame = new CGRect(0, Bounds.Y + Frame.Size.Height - 260, Frame.Size.Width, 260);
}
else
{
selectionPicker.Frame = new CGRect(0, Bounds.Y + Frame.Size.Height - 150, Frame.Size.Width, 150);
}
}
else
view.Frame = Frame;
}
base.LayoutSubviews();
}
}
public class PickerViewModel : UIPickerViewModel
{
UIButton selectionTypeTextButton;
SFChart chart1;
public PickerViewModel(SFChart chart, UIButton selectionButton)
{
selectionTypeTextButton = selectionButton;
chart1 = chart;
}
private readonly IList<string> selectionModes = new List<string>
{
"Data Point Selection",
"Series Selection",
};
public override nint GetComponentCount(UIPickerView pickerView)
{
return 1;
}
public override nint GetRowsInComponent(UIPickerView pickerView, nint component)
{
return (nint)selectionModes.Count;
}
public override string GetTitle(UIPickerView pickerView, nint row, nint component)
{
return selectionModes[(int)row];
}
public override void Selected(UIPickerView pickerView, nint row, nint component)
{
selectionTypeTextButton.SetTitle(selectionModes[(int)row], UIControlState.Normal);
if (row == 0)
{
chart1.EnableSeriesSelection = false;
}
else if (row == 1)
{
chart1.EnableSeriesSelection = true;
}
}
}
}