forked from syncfusion/xamarin-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Trackball.cs
188 lines (162 loc) · 7.31 KB
/
Trackball.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
#region Copyright Syncfusion Inc. 2001-2021.
// Copyright Syncfusion Inc. 2001-2021. 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 Android.App;
using Android.Content;
using Android.Graphics;
using Android.OS;
using Android.Views;
using Android.Widget;
using Com.Syncfusion.Charts;
using Com.Syncfusion.Charts.Enums;
using Com.Syncfusion.Navigationdrawer;
using System;
using System.Collections.Generic;
namespace SampleBrowser
{
[Activity(Label = "Trackball")]
public class Trackball : SamplePage
{
SfChart chart;
public override View GetSampleContent(Context context)
{
chart = new SfChart(context);
chart.SetBackgroundColor(Color.White);
chart.Title.Text = "Average sales for person";
chart.Legend.Visibility = Visibility.Visible;
chart.Legend.DockPosition = ChartDock.Bottom;
chart.Legend.IconHeight = 14;
chart.Legend.IconWidth = 14;
DateTimeAxis primaryAxis = new DateTimeAxis();
primaryAxis.PlotOffset = 5;
primaryAxis.AxisLineOffset = 5;
primaryAxis.ShowMajorGridLines = false;
primaryAxis.Interval = 1;
primaryAxis.EdgeLabelsDrawingMode = EdgeLabelsDrawingMode.Shift;
primaryAxis.EdgeLabelsVisibilityMode = EdgeLabelsVisibilityMode.Visible;
primaryAxis.LabelStyle.LabelFormat = "yyyy";
chart.PrimaryAxis = primaryAxis;
chart.PrimaryAxis.ShowMajorGridLines = false;
chart.SecondaryAxis = new NumericalAxis { };
chart.SecondaryAxis.MajorTickStyle.TickSize = 0;
chart.SecondaryAxis.LineStyle.StrokeWidth = 0;
(chart.SecondaryAxis as NumericalAxis).Maximum = 80;
(chart.SecondaryAxis as NumericalAxis).Minimum = 10;
(chart.SecondaryAxis as NumericalAxis).Interval = 10;
chart.SecondaryAxis.Title.Text = "Revenue";
chart.SecondaryAxis.LabelStyle.LabelFormat = "#'M '";
var series = new LineSeries
{
ItemsSource = MainPage.GetSeriesData1(),
XBindingPath = "Date",
YBindingPath = "YValue",
Label = "John",
Color = Color.ParseColor("#00BDAE"),
StrokeWidth= 3
};
series.DataMarker.MarkerStrokeColor = Color.ParseColor("#00BDAE");
series.DataMarker.ShowMarker = true;
series.DataMarker.MarkerColor = Color.White;
series.DataMarker.MarkerStrokeWidth = 2;
series.DataMarker.MarkerWidth = 6;
series.DataMarker.MarkerHeight = 6;
chart.Series.Add(series);
series = new LineSeries
{
ItemsSource = MainPage.GetSeriesData2(),
XBindingPath = "Date",
YBindingPath = "YValue",
Color = Color.ParseColor("#404041"),
Label = "Andrew",
StrokeWidth = 3
};
series.DataMarker.MarkerStrokeColor = Color.ParseColor("#404041");
series.DataMarker.ShowMarker = true;
series.DataMarker.MarkerColor = Color.White;
series.DataMarker.MarkerStrokeWidth = 2;
series.DataMarker.MarkerWidth = 6;
series.DataMarker.MarkerHeight = 6;
chart.Series.Add(series);
series = new LineSeries
{
ItemsSource = MainPage.GetSeriesData3(),
XBindingPath = "Date",
YBindingPath = "YValue",
Color = Color.ParseColor("#357CD2"),
Label = "Thomas",
StrokeWidth = 3
};
series.DataMarker.MarkerStrokeColor = Color.ParseColor("#357CD2");
series.DataMarker.ShowMarker = true;
series.DataMarker.MarkerColor = Color.White;
series.DataMarker.MarkerStrokeWidth = 2;
series.DataMarker.MarkerWidth = 6;
series.DataMarker.MarkerHeight = 6;
chart.Series.Add(series);
chart.Behaviors.Add(new ChartTrackballBehavior());
var label = new TextView(context);
label.SetPadding(5, 5, 5, 5);
label.Text = "Press and hold to enable trackball.";
var layout = new LinearLayout(context){ Orientation = Android.Widget.Orientation.Vertical };
var layoutLabel = new LinearLayout(context)
{
Orientation = Android.Widget.Orientation.Horizontal,
LayoutParameters =
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent)
};
layoutLabel.SetHorizontalGravity(GravityFlags.CenterHorizontal);
layoutLabel.AddView(label);
layout.AddView(layoutLabel);
layout.AddView(chart);
return layout;
}
public override View GetPropertyWindowLayout(Android.Content.Context context)
{
/**
* Property Window
* */
int width = (context.Resources.DisplayMetrics.WidthPixels) / 2;
LinearLayout propertylayout = new LinearLayout(context); //= new LinearLayout(context);
propertylayout.Orientation = Android.Widget.Orientation.Vertical;
LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(
width * 2, 5);
layoutParams1.SetMargins(0, 20, 0, 0);
TextView labelDisplayMode = new TextView(context);
labelDisplayMode.TextSize = 20;
labelDisplayMode.Text = "LabelDisplay Mode";
Spinner selectLabelMode = new Spinner(context,SpinnerMode.Dialog);
List<String> adapter = new List<String>() { "FloatAllPoints", "NearestPoint", "GroupAllPoints" };
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>
(context, Android.Resource.Layout.SimpleSpinnerItem, adapter);
dataAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleDropDownItem1Line);
selectLabelMode.Adapter = dataAdapter;
selectLabelMode.ItemSelected += (object sender, AdapterView.ItemSelectedEventArgs e) =>
{
String selectedItem = dataAdapter.GetItem(e.Position);
ChartTrackballBehavior trackballBehavior = (chart.Behaviors[0] as ChartTrackballBehavior);
if (selectedItem.Equals("NearestPoint"))
{
trackballBehavior.LabelDisplayMode = TrackballLabelDisplayMode.NearestPoint;
}
else if (selectedItem.Equals("FloatAllPoints"))
{
trackballBehavior.LabelDisplayMode = TrackballLabelDisplayMode.FloatAllPoints;
}
else if (selectedItem.Equals("GroupAllPoints"))
{
trackballBehavior.LabelDisplayMode = TrackballLabelDisplayMode.GroupAllPoints;
}
};
propertylayout.AddView(labelDisplayMode);
SeparatorView separate = new SeparatorView(context, width * 2);
separate.LayoutParameters = new ViewGroup.LayoutParams(width * 2, 5);
propertylayout.AddView(separate, layoutParams1);
propertylayout.AddView(selectLabelMode);
return propertylayout;
}
}
}