forked from syncfusion/xamarin-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColumn.cs
179 lines (157 loc) · 6.02 KB
/
Column.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
#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;
using System.Drawing;
#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 Column : SampleView
{
SFChart chart;
public Column()
{
chart = new SFChart();
chart.Title.Text = new NSString("Olympic Medal Counts - RIO");
chart.ColorModel.Palette = SFChartColorPalette.Natural;
SFCategoryAxis primary = new SFCategoryAxis();
primary.LabelPlacement = SFChartLabelPlacement.BetweenTicks;
primary.EdgeLabelsDrawingMode = SFChartAxisEdgeLabelsDrawingMode.Shift;
primary.ShowMajorGridLines = false;
chart.PrimaryAxis = primary;
chart.SecondaryAxis = new SFNumericalAxis();
chart.SecondaryAxis.ShowMajorGridLines = false;
chart.SecondaryAxis.Visible = false;
ChartViewModel dataModel = new ChartViewModel();
SFColumnSeries series1 = new SFColumnSeries();
series1.ItemsSource = dataModel.ColumnData1;
series1.XBindingPath = "XValue";
series1.YBindingPath = "YValue";
series1.EnableTooltip = true;
series1.Label = "Gold";
series1.EnableAnimation = true;
series1.LegendIcon = SFChartLegendIcon.SeriesType;
series1.DataMarker.ShowLabel = true;
series1.DataMarker.LabelStyle.LabelPosition = SFChartDataMarkerLabelPosition.Inner;
chart.Series.Add(series1);
SFColumnSeries series2 = new SFColumnSeries();
series2.ItemsSource = dataModel.ColumnData2;
series2.XBindingPath = "XValue";
series2.YBindingPath = "YValue";
series2.EnableTooltip = true;
series2.Label = "Silver";
series2.EnableAnimation = true;
series2.LegendIcon = SFChartLegendIcon.SeriesType;
series2.DataMarker.ShowLabel = true;
series2.DataMarker.LabelStyle.LabelPosition = SFChartDataMarkerLabelPosition.Inner;
chart.Series.Add(series2);
SFColumnSeries series3 = new SFColumnSeries();
series3.ItemsSource = dataModel.ColumnData3;
series3.XBindingPath = "XValue";
series3.YBindingPath = "YValue";
series3.EnableTooltip = true;
series3.Label = "Silver";
series3.EnableAnimation = true;
series3.LegendIcon = SFChartLegendIcon.SeriesType;
series3.DataMarker.ShowLabel = true;
series3.DataMarker.LabelStyle.LabelPosition = SFChartDataMarkerLabelPosition.Inner;
chart.Series.Add(series3);
chart.Legend.Visible = true;
chart.Legend.IconWidth = 14;
chart.Legend.IconHeight = 14;
chart.Legend.ToggleSeriesVisibility = true;
chart.Legend.DockPosition = SFChartLegendPosition.Bottom;
this.AddSubview(chart);
this.OptionView = new UIView();
}
public override void LayoutSubviews()
{
foreach (var view in this.Subviews)
{
view.Frame = Bounds;
}
this.CreateOptionView();
base.LayoutSubviews();
}
private void CreateOptionView()
{
UILabel spacingLbl = new UILabel();
spacingLbl.Text = "Spacing:";
spacingLbl.TextAlignment = UITextAlignment.Left;
spacingLbl.Font = UIFont.FromName("Helvetica", 14f);
UILabel widthLbl = new UILabel();
widthLbl.Text = "SegmentWidth:";
widthLbl.TextAlignment = UITextAlignment.Left;
widthLbl.Font = UIFont.FromName("Helvetica", 14f);
UILabel spacing = new UILabel();
spacing.Text = "0.0";
spacing.Font = UIFont.FromName("Helvetica", 14f);
UILabel width = new UILabel();
width.Text = "0.8";
width.Font = UIFont.FromName("Helvetica", 14f);
UISlider spacingSlider = new UISlider();
spacingSlider.MinValue = 0.0f;
spacingSlider.MaxValue = 1.0f;
spacingSlider.Value = 0.0f;
spacingSlider.ValueChanged += (object sender, EventArgs e) =>
{
(chart.SeriesAtIndex(0) as SFColumnSeries).Spacing = (float)spacingSlider.Value;
(chart.SeriesAtIndex(1) as SFColumnSeries).Spacing = (float)spacingSlider.Value;
decimal value = decimal.Parse(spacingSlider.Value.ToString());
spacing.Text = value.ToString("0.00");
};
UISlider widthSlider = new UISlider();
widthSlider.MinValue = 0.0f;
widthSlider.MaxValue = 1.0f;
widthSlider.Value = 0.8f;
widthSlider.ValueChanged += (object sender, EventArgs e) =>
{
(chart.SeriesAtIndex(0) as SFColumnSeries).Width = (float)widthSlider.Value;
(chart.SeriesAtIndex(1) as SFColumnSeries).Width = (float)widthSlider.Value;
decimal value = decimal.Parse(widthSlider.Value.ToString());
width.Text = value.ToString("0.00");
};
if (Utility.IsIPad)
{
spacingLbl.Frame = new CGRect(10, 25, 80, 40);
spacing.Frame = new CGRect(spacingLbl.Frame.Size.Width, 25, 50, 40);
widthLbl.Frame = new CGRect(10, 130, 120, 40);
width.Frame = new CGRect(widthLbl.Frame.Size.Width, 130, 50, 40);
spacingSlider.Frame = new RectangleF(10, 50, (float)PopoverSize.Width - 20, 60);
widthSlider.Frame = new RectangleF(10, 155, (float)PopoverSize.Width - 20, 60);
}
else
{
spacingLbl.Frame = new CGRect(10, 25, 80, 40);
spacing.Frame = new CGRect(spacingLbl.Frame.Size.Width, 25, 50, 40);
widthLbl.Frame = new CGRect(10, 130, 120, 40);
width.Frame = new CGRect(widthLbl.Frame.Size.Width, 130, 50, 40);
spacingSlider.Frame = new RectangleF(10, 50, (float)this.Frame.Width - 20, 60);
widthSlider.Frame = new RectangleF(10, 155, (float)this.Frame.Width - 20, 60);
}
this.OptionView.AddSubview(spacingLbl);
this.OptionView.AddSubview(widthLbl);
this.OptionView.AddSubview(spacing);
this.OptionView.AddSubview(width);
this.OptionView.AddSubview(spacingSlider);
this.OptionView.AddSubview(widthSlider);
}
}
}