forked from syncfusion/xamarin-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGradientChart.cs
88 lines (77 loc) · 3.21 KB
/
GradientChart.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
#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 System.Drawing;
using CoreGraphics;
using Foundation;
using Syncfusion.Drawing;
using Syncfusion.SfChart.iOS;
using UIKit;
namespace SampleBrowser
{
public class GradientChart : SampleView
{
public GradientChart()
{
SFChart chart = new SFChart();
chart.Title.Text = (NSString)"Oxygen Level";
chart.ColorModel.Palette = SFChartColorPalette.Custom;
ChartGradientColor gradientColor = new ChartGradientColor() { StartPoint = new CGPoint(0.5f, 1), EndPoint = new CGPoint(0.5f, 0) };
ChartGradientStop stopColor1 = new ChartGradientStop() { Color = UIColor.White, Offset = 0 };
ChartGradientStop stopColor2 = new ChartGradientStop() { Color = UIColor.FromRGBA(0, 128f / 255f, 223f / 255f, 1.0f), Offset = 1 };
gradientColor.GradientStops.Add(stopColor1);
gradientColor.GradientStops.Add(stopColor2);
ChartGradientColorCollection gradientColorsCollection = new ChartGradientColorCollection()
{
gradientColor
};
chart.ColorModel.CustomGradientColors = gradientColorsCollection;
chart.PrimaryAxis = new SFDateTimeAxis() { PlotOffset = 6, EdgeLabelsDrawingMode = SFChartAxisEdgeLabelsDrawingMode.Shift, ShowMajorGridLines = false, ShowMinorGridLines = false };
NSDateFormatter formatter = new NSDateFormatter();
formatter.DateFormat = new NSString("MMM dd");
chart.PrimaryAxis.LabelStyle.LabelFormatter = formatter;
chart.SecondaryAxis = new SFNumericalAxis
{
Maximum = new NSNumber(50),
Interval = new NSNumber(5)
};
NSNumberFormatter secondaryAxisFormatter = new NSNumberFormatter();
secondaryAxisFormatter.PositiveSuffix = "%";
chart.SecondaryAxis.LabelStyle.LabelFormatter = secondaryAxisFormatter;
ChartViewModel dataModel = new ChartViewModel();
SFSplineAreaSeries series = new SFSplineAreaSeries();
series.ItemsSource = dataModel.GradientData;
series.XBindingPath = "XValue";
series.YBindingPath = "YValue";
series.BorderColor = UIColor.FromRGBA(0, 128f / 255f, 223f / 255f, 1.0f);
series.BorderWidth = 2;
series.DataMarker.ShowLabel = true;
series.DataMarker.MarkerWidth = 8;
series.DataMarker.MarkerHeight = 8;
series.DataMarker.MarkerColor = UIColor.White;
series.DataMarker.MarkerBorderColor = UIColor.FromRGBA(0, 128f / 255f, 223f / 255f, 1.0f);
series.DataMarker.MarkerBorderWidth = 2;
series.DataMarker.ShowMarker = true;
series.DataMarker.LabelStyle.OffsetY = -10;
series.DataMarker.LabelStyle.BackgroundColor = UIColor.FromRGBA(0, 128f / 255f, 223f / 255f, 1.0f);
NSNumberFormatter dataMarkerFormatter = new NSNumberFormatter();
dataMarkerFormatter.PositiveSuffix = "%";
series.DataMarker.LabelStyle.LabelFormatter = dataMarkerFormatter;
chart.Series.Add(series);
this.AddSubview(chart);
}
public override void LayoutSubviews()
{
foreach (var view in this.Subviews)
{
view.Frame = Bounds;
}
base.LayoutSubviews();
}
}
}