Example #1
0
        private void ChartAnnotationsProvider_AnnotationCreated(object sender, ChartAnnotationCreatedEventArgs e)
        {
            ChartAnnotationsProvider   provider       = sender as ChartAnnotationsProvider;
            DailyLimitationViewModel   dailyContext   = e.Context as DailyLimitationViewModel;
            MonthlyLimitationViewModel monthlyContext = e.Context as MonthlyLimitationViewModel;

            if (dailyContext != null)
            {
                CartesianGridLineAnnotation lineAnnotation = new CartesianGridLineAnnotation();
                lineAnnotation.Value = dailyContext.StartValue;
                Binding axisBinding = new Binding("VerticalAxis")
                {
                    RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor)
                    {
                        AncestorType = typeof(RadCartesianChart)
                    }
                };
                BindingOperations.SetBinding(lineAnnotation, CartesianGridLineAnnotation.AxisProperty, axisBinding);
                lineAnnotation.Stroke          = new SolidColorBrush(Colors.Red);
                lineAnnotation.StrokeThickness = 2;
                e.Annotation = lineAnnotation;
            }
            else if (monthlyContext != null)
            {
                CartesianMarkedZoneAnnotation markedZoneAnnotation = new CartesianMarkedZoneAnnotation();
                markedZoneAnnotation.HorizontalFrom = monthlyContext.StartMonth;
                markedZoneAnnotation.HorizontalTo   = monthlyContext.EndMonth;
                markedZoneAnnotation.VerticalFrom   = monthlyContext.StartValue;
                markedZoneAnnotation.VerticalTo     = monthlyContext.EndValue;
                markedZoneAnnotation.Fill           = new SolidColorBrush(Colors.Green);
                e.Annotation = markedZoneAnnotation;
            }
        }
        private void ChartAnnotationsProvider_AnnotationCreated(object sender, ChartAnnotationCreatedEventArgs e)
        {
            ChartAnnotationsProvider provider = sender as ChartAnnotationsProvider;
            DailyLimitationViewModel dailyContext = e.Context as DailyLimitationViewModel;
            MonthlyLimitationViewModel monthlyContext = e.Context as MonthlyLimitationViewModel;

            if (dailyContext != null)
            {
                CartesianGridLineAnnotation lineAnnotation = new CartesianGridLineAnnotation();
                lineAnnotation.Value = dailyContext.StartValue;
                Binding axisBinding = new Binding("VerticalAxis") { RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = typeof(RadCartesianChart) } };
                BindingOperations.SetBinding(lineAnnotation, CartesianGridLineAnnotation.AxisProperty, axisBinding);
                lineAnnotation.Stroke = new SolidColorBrush(Colors.Red);
                lineAnnotation.StrokeThickness = 2;
                e.Annotation = lineAnnotation;
            }
            else if (monthlyContext != null)
            {
                CartesianMarkedZoneAnnotation markedZoneAnnotation = new CartesianMarkedZoneAnnotation();
                markedZoneAnnotation.HorizontalFrom = monthlyContext.StartMonth;
                markedZoneAnnotation.HorizontalTo = monthlyContext.EndMonth;
                markedZoneAnnotation.VerticalFrom = monthlyContext.StartValue;
                markedZoneAnnotation.VerticalTo = monthlyContext.EndValue;
                markedZoneAnnotation.Fill = new SolidColorBrush(Colors.Green);
                e.Annotation = markedZoneAnnotation;
            }
        }
		private RadCartesianChartView createChart(){
			//Create the Chart View
			RadCartesianChartView chart = new RadCartesianChartView(this.Activity);

			//Create the bar series and attach axes and value bindings.
			BarSeries barSeries = new BarSeries();

			barSeries.ValueBinding  = new ValueBinding();
			barSeries.CategoryBinding = new CategoryBinding();

			LinearAxis verticalAxis = new LinearAxis();
			//The values in the linear axis will not have values after the decimal point.
			verticalAxis.LabelFormat = "%.0f";
			CategoricalAxis horizontalAxis = new CategoricalAxis();
			barSeries.VerticalAxis = verticalAxis;
			barSeries.HorizontalAxis = horizontalAxis;

			//Bind series to data
			barSeries.Data  = this.getData();

			//Add series to chart
			chart.Series.Add(barSeries);

			CartesianGridLineAnnotation annotation = new CartesianGridLineAnnotation(verticalAxis, 3);
			chart.Annotations.Add(annotation);
			annotation.LabelHorizontalAlignment = HorizontalAlignment.Left;
			annotation.StrokeColor = Color.Argb(255, 235, 100, 32);
			annotation.StrokeWidth = 4;
			annotation.ZIndex = 1001;
			annotation.Label = "This is Grid Line annotation";

			return chart;
		}
        public CartesianGridLineAnnotation CreateLine()
        {
            var annotation = new CartesianGridLineAnnotation();

            annotation.Stroke = Brushes.Black;
            annotation.Axis   = this.horizontalAxis;
            annotation.Value  = GetAxisCenter();
            annotation.Tag    = "CustomAxisElement";
            return(annotation);
        }
 private static void UpdateGridLineAnnotation(CartesianGridLineAnnotation annotation, DataTuple dataTuple)
 {
     if (annotation.Chart != null)
     {
         var chart = (RadCartesianChart)annotation.Chart;
         if (annotation.Axis == chart.VerticalAxis)
         {
             annotation.Value = dataTuple.SecondValue;
         }
         else
         {
             annotation.Value = dataTuple.FirstValue;
         }
     }
 }
        private void UpdateChartAnnotation()
        {
            CartesianGridLineAnnotation myLineAnnotation = new CartesianGridLineAnnotation
            {
                Axis   = Chart.HorizontalAxis,
                Value  = ChartEventItems[ChartEventItems.Count - 1].EventStart,
                Stroke = new SolidColorBrush(Windows.UI.Colors.Red)
            };

            Chart.Annotations.Add(myLineAnnotation);

            var newLabel = new CartesianCustomAnnotation
            {
                HorizontalAxis = horizontalAxis,
                VerticalAxis   = verticalAxis
            };

            var border = new Border
            {
                //Background = new SolidColorBrush(Windows.UI.Colors.Gray),
                VerticalAlignment = VerticalAlignment.Top,
                Opacity           = 0.9
            };

            var content = new TextBlock
            {
                Text = ChartEventItems[ChartEventItems.Count - 1].EventDescription
            };

            border.Child             = content;
            newLabel.Content         = border;
            newLabel.HorizontalValue = ChartEventItems[ChartEventItems.Count - 1].EventStart;

            newLabel.HorizontalAlignment = HorizontalAlignment.Left;
            newLabel.VerticalAlignment   = VerticalAlignment.Top;
            newLabel.VerticalValue       = 80d;                    // Position on Y axis
            newLabel.Tag            = "label";
            newLabel.Visibility     = Visibility.Visible;
            newLabel.ClipToPlotArea = false;
            Chart.Annotations.Add(newLabel);
        }
Example #7
0
        private RadCartesianChartView createChart()
        {
            //Create the Chart View
            RadCartesianChartView chart = new RadCartesianChartView(this.Activity);

            //Create the bar series and attach axes and value bindings.
            BarSeries barSeries = new BarSeries();

            barSeries.ValueBinding    = new ValueBinding();
            barSeries.CategoryBinding = new CategoryBinding();

            LinearAxis verticalAxis = new LinearAxis();

            //The values in the linear axis will not have values after the decimal point.
            verticalAxis.LabelFormat = "%.0f";
            CategoricalAxis horizontalAxis = new CategoricalAxis();

            barSeries.VerticalAxis   = verticalAxis;
            barSeries.HorizontalAxis = horizontalAxis;

            //Bind series to data
            barSeries.Data = this.getData();

            //Add series to chart
            chart.Series.Add(barSeries);

            CartesianGridLineAnnotation annotation = new CartesianGridLineAnnotation(verticalAxis, 3);

            chart.Annotations.Add(annotation);
            annotation.LabelHorizontalAlignment = HorizontalAlignment.Left;
            annotation.StrokeColor = Color.Argb(255, 235, 100, 32);
            annotation.StrokeWidth = 4;
            annotation.ZIndex      = 1001;
            annotation.Label       = "This is Grid Line annotation";

            return(chart);
        }
Example #8
0
        public MainPage()
        {
            InitializeComponent();

            BackgroundColor = Xamarin.Forms.Device.OnPlatform(Xamarin.Forms.Color.White, Xamarin.Forms.Color.White, Xamarin.Forms.Color.Transparent);

            var chart = new RadCartesianChart
            {
                HorizontalAxis = new Telerik.XamarinForms.Chart.CategoricalAxis()
                {
                    LabelFitMode = AxisLabelFitMode.MultiLine,
                },
                VerticalAxis = new Telerik.XamarinForms.Chart.NumericalAxis()
                {
                    LabelFitMode         = AxisLabelFitMode.MultiLine,
                    RangeExtendDirection = NumericalAxisRangeExtendDirection.Both,
                    MajorStep            = 30,
                },
            };

            var series = new BarSeries();

            chart.Series.Add(series);

            this.Content = chart;

            series.ValueBinding = new Telerik.XamarinForms.Chart.PropertyNameDataPointBinding
            {
                PropertyName = "Value"
            };

            series.CategoryBinding = new Telerik.XamarinForms.Chart.PropertyNameDataPointBinding
            {
                PropertyName = "Category"
            };

            series.ItemsSource = MainViewModel.GetCategoricalData();

            var grid = new CartesianChartGrid();

            grid.MajorLinesVisibility = GridLineVisibility.Y;
            grid.MajorYLineDashArray  = Device.OnPlatform(null, new double[] { 4, 2 }, new double[] { 4, 2 });
            grid.StripLinesVisibility = GridLineVisibility.Y;

            grid.YStripeColor            = Color.FromRgba(99, 99, 99, 100);
            grid.YStripeAlternativeColor = Color.FromRgba(169, 169, 169, 31);
            grid.MajorLineColor          = Color.FromRgb(211, 211, 211);
            grid.MajorLineThickness      = Device.OnPlatform(0.5, 2, 2);

            chart.Grid = grid;

            var treshold      = MainViewModel.GetCategoricalData().Average(c => c.Value);
            var startTreshold = treshold * 0.95;
            var endTreshold   = treshold * 1.05;

            var lineAnnotation = new CartesianGridLineAnnotation()
            {
                Axis            = chart.VerticalAxis,
                Value           = treshold,
                Stroke          = Color.FromRgb(255, 0, 0),
                StrokeThickness = Device.OnPlatform(0.5, 2, 2),
                DashArray       = new double[] { 4, 2 },
            };

            var bandAnnotation = new CartesianPlotBandAnnotation()
            {
                Axis            = chart.VerticalAxis,
                From            = startTreshold,
                To              = endTreshold,
                Fill            = Color.FromRgba(255, 0, 0, 50),
                StrokeThickness = 2,
                Stroke          = Color.Transparent,
            };

            chart.Annotations.Add(bandAnnotation);
            chart.Annotations.Add(lineAnnotation);
        }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the ChartAnnotationAutomationPeer class.
 /// </summary>
 public CartesianGridLineAnnotationAutomationPeer(CartesianGridLineAnnotation owner)
     : base(owner)
 {
 }
Example #10
0
        public MainPage()
        {
            InitializeComponent();

            BackgroundColor = Xamarin.Forms.Device.OnPlatform(Xamarin.Forms.Color.White, Xamarin.Forms.Color.White, Xamarin.Forms.Color.Transparent);

            var chart = new RadCartesianChart
            {
                HorizontalAxis = new Telerik.XamarinForms.Chart.CategoricalAxis()
                {
                    LabelFitMode = AxisLabelFitMode.MultiLine,
                },
                VerticalAxis = new Telerik.XamarinForms.Chart.NumericalAxis()
                {
                    LabelFitMode = AxisLabelFitMode.MultiLine,
                    RangeExtendDirection = NumericalAxisRangeExtendDirection.Both,
                    MajorStep = 30,
                },
            };

            var series = new BarSeries();
            chart.Series.Add(series);

            this.Content = chart;

            series.ValueBinding = new Telerik.XamarinForms.Chart.PropertyNameDataPointBinding
            {
                PropertyName = "Value"
            };

            series.CategoryBinding = new Telerik.XamarinForms.Chart.PropertyNameDataPointBinding
            {
                PropertyName = "Category"
            };

            series.ItemsSource = MainViewModel.GetCategoricalData();

            var grid = new CartesianChartGrid();

            grid.MajorLinesVisibility = GridLineVisibility.Y;
            grid.MajorYLineDashArray = Device.OnPlatform(null, new double[] { 4, 2 }, new double[] { 4, 2 });
            grid.StripLinesVisibility = GridLineVisibility.Y;

            grid.YStripeColor = Color.FromRgba(99, 99, 99, 100);
            grid.YStripeAlternativeColor = Color.FromRgba(169, 169, 169, 31);
            grid.MajorLineColor = Color.FromRgb(211, 211, 211);
            grid.MajorLineThickness = Device.OnPlatform(0.5, 2, 2);

            chart.Grid = grid;

            var treshold = MainViewModel.GetCategoricalData().Average(c => c.Value);
            var startTreshold = treshold * 0.95;
            var endTreshold = treshold * 1.05;

            var lineAnnotation = new CartesianGridLineAnnotation()
            {
                Axis = chart.VerticalAxis,
                Value = treshold,
                Stroke = Color.FromRgb(255, 0, 0),
                StrokeThickness = Device.OnPlatform(0.5, 2, 2),
                DashArray = new double[] { 4, 2 },
            };

            var bandAnnotation = new CartesianPlotBandAnnotation()
            {
                Axis = chart.VerticalAxis,
                From = startTreshold,
                To = endTreshold,
                Fill = Color.FromRgba(255, 0, 0, 50),
                StrokeThickness = 2,
                Stroke = Color.Transparent,
            };

            chart.Annotations.Add(bandAnnotation);
            chart.Annotations.Add(lineAnnotation);
        }
Example #11
0
        public GridLineAnnotationsPage()
        {
            InitializeComponent();

            var model = new MainViewModel();
            var data  = MainViewModel.GetCategoricalData();

            model.Data1 = data;

            var treshold      = data.Average(c => c.Value);
            var startTreshold = treshold * 0.95;
            var endTreshold   = treshold * 1.05;


            var chart = new Telerik.XamarinForms.Chart.RadCartesianChart
            {
                HorizontalAxis = new Telerik.XamarinForms.Chart.CategoricalAxis()
                {
                    LabelFitMode = Telerik.XamarinForms.Chart.AxisLabelFitMode.MultiLine,
                },
                VerticalAxis  = new Telerik.XamarinForms.Chart.NumericalAxis(),
                HeightRequest = 400
            };


            var series = new Telerik.XamarinForms.Chart.BarSeries();

            series.ItemsSource = model.Data1;

            series.ValueBinding = new Telerik.XamarinForms.Chart.PropertyNameDataPointBinding
            {
                PropertyName = "Value"
            };

            series.CategoryBinding = new Telerik.XamarinForms.Chart.PropertyNameDataPointBinding
            {
                PropertyName = "Category"
            };

            chart.Series.Add(series);

            var lineAnnotation = new CartesianGridLineAnnotation()
            {
                Axis            = chart.VerticalAxis,
                Value           = treshold,
                Stroke          = Color.FromHex("0E72F6"),
                StrokeThickness = Device.OnPlatform(0.5, 2, 2),
                DashArray       = new double[] { 4, 2 }
            };

            var bandAnnotation = new CartesianPlotBandAnnotation()
            {
                Axis            = chart.VerticalAxis,
                From            = startTreshold,
                To              = endTreshold,
                Fill            = Color.FromHex("33A9A9A9"),
                StrokeThickness = 2,
                Stroke          = Color.Transparent,
            };

            chart.Annotations.Add(lineAnnotation);
            chart.Annotations.Add(bandAnnotation);

            this.Content = chart;
        }