コード例 #1
0
        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);
        }
コード例 #2
0
        public override View GetSampleContent(Context context)
        {
            chart            = new SfChart(context);
            chart.Title.Text = "Oxygen Level";
            chart.SetBackgroundColor(Color.White);

            chart.ColorModel.ColorPalette = ChartColorPalette.Custom;

            ChartGradientColor gradientColor = new ChartGradientColor()
            {
                StartPoint = new PointF(0.5f, 1), EndPoint = new PointF(0.5f, 0)
            };
            ChartGradientStop stopColor1 = new ChartGradientStop()
            {
                Color = Color.White, Offset = 0
            };
            ChartGradientStop stopColor2 = new ChartGradientStop()
            {
                Color = Color.ParseColor("#FF0080DF"), Offset = 1
            };

            gradientColor.GradientStops.Add(stopColor1);
            gradientColor.GradientStops.Add(stopColor2);

            ChartGradientColorCollection gradientColorsCollection = new ChartGradientColorCollection()
            {
                gradientColor
            };

            chart.ColorModel.CustomGradientColors = gradientColorsCollection;

            DateTimeAxis primaryAxis = new DateTimeAxis();

            primaryAxis.PlotOffset             = 6;
            primaryAxis.EdgeLabelsDrawingMode  = EdgeLabelsDrawingMode.Shift;
            primaryAxis.ShowMinorGridLines     = false;
            primaryAxis.ShowMajorGridLines     = false;
            primaryAxis.LabelStyle.LabelFormat = "MMM dd";
            chart.PrimaryAxis = primaryAxis;

            NumericalAxis numericalAxis = new NumericalAxis();

            numericalAxis.Maximum  = 50;
            numericalAxis.Interval = 5;
            numericalAxis.LabelStyle.LabelFormat = "#'%'";
            chart.SecondaryAxis = numericalAxis;

            SplineAreaSeries splineAreaSeries = new SplineAreaSeries();

            splineAreaSeries.ItemsSource                           = MainPage.GetGradientData();
            splineAreaSeries.XBindingPath                          = "Date";
            splineAreaSeries.YBindingPath                          = "High";
            splineAreaSeries.StrokeColor                           = Color.ParseColor("#FF0080DF");
            splineAreaSeries.StrokeWidth                           = 2;
            splineAreaSeries.DataMarker.ShowLabel                  = true;
            splineAreaSeries.DataMarker.MarkerWidth                = 8;
            splineAreaSeries.DataMarker.MarkerHeight               = 8;
            splineAreaSeries.DataMarker.MarkerColor                = Color.White;
            splineAreaSeries.DataMarker.MarkerStrokeColor          = Color.ParseColor("#FF0080DF");
            splineAreaSeries.DataMarker.MarkerStrokeWidth          = 2;
            splineAreaSeries.DataMarker.ShowMarker                 = true;
            splineAreaSeries.DataMarker.LabelStyle.OffsetY         = -10;
            splineAreaSeries.DataMarker.LabelStyle.BackgroundColor = Color.ParseColor("#FF0080DF");
            splineAreaSeries.DataMarker.LabelStyle.LabelFormat     = "#.#'%'";

            chart.Series.Add(splineAreaSeries);
            return(chart);
        }