예제 #1
0
        private static RadCartesianChart CreateChart()
        {
            // >> chart-getting-started-csharp-chart
            var chart = new RadCartesianChart
            {
                HorizontalAxis = new CategoricalAxis(),
                VerticalAxis   = new NumericalAxis(),
                BindingContext = new GettingStarted.ViewModel()
            };

            var series = new BarSeries();

            series.SetBinding(ChartSeries.ItemsSourceProperty, new Binding("Data"));

            series.ValueBinding = new PropertyNameDataPointBinding {
                PropertyName = "Value"
            };
            series.CategoryBinding = new PropertyNameDataPointBinding {
                PropertyName = "Category"
            };

            chart.Series.Add(series);
            // << chart-getting-started-csharp-chart

            return(chart);
        }
예제 #2
0
        private static BarSeries ProvideBarSeries(PropertyInfo propertyInfo, string dependentValuePath,
                                                  string independentValuePath)
        {
            var series = new BarSeries();

            series.SetBinding(DataPointSeries.ItemsSourceProperty, propertyInfo.GetBinding());
            series.IndependentValuePath = independentValuePath;
            series.DependentValuePath   = dependentValuePath;

            series.Unloaded += (o, e) =>
            {
                var control = o as BarSeries;
                if (control == null)
                {
                    return;
                }

                BindingOperations.ClearAllBindings(control);
            };

            return(series);
        }
예제 #3
0
        private void SetOverallDescription()
        {
            UpdateOverallScore();
            borderFrame.BindingContext = Ot;
            StackLayout score = new StackLayout()
            {
                VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.Center
            };
            Label scoreLabel = new Label()
            {
                TextColor = Color.White, FontAttributes = FontAttributes.Bold, FontSize = 12f, VerticalOptions = LayoutOptions.Center, VerticalTextAlignment = TextAlignment.Center, HorizontalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.Center
            };
            Binding b = new Binding("OverallAll");

            b.StringFormat = "{0}%";
            scoreLabel.SetBinding(Label.TextProperty, b);
            score.Children.Add(scoreLabel);
            borderFrame.Content = score;
            borderFrame.SetBinding(Frame.BackgroundColorProperty, new Binding("OverallColor"));
            borderFrame.Parent = overallScore;


            StackLayout Holder = new StackLayout();

            chart = new SfChart()
            {
                SideBySideSeriesPlacement = false, HeightRequest = 150, BackgroundColor = Color.Transparent, HorizontalOptions = LayoutOptions.StartAndExpand, WidthRequest = Application.Current.MainPage.Width
            };
            //Initializing Primary Axis

            chart.SideBySideSeriesPlacement = false;
            CategoryAxis primaryAxis = new CategoryAxis()
            {
                LabelStyle = new ChartAxisLabelStyle()
                {
                    TextColor = Color.White, LabelAlignment = ChartAxisLabelAlignment.Center, LabelsPosition = AxisElementPosition.Outside, WrappedLabelAlignment = ChartAxisLabelAlignment.Center
                }, OpposedPosition = false
            };

            //Initializing Secondary Axis
            NumericalAxis secondaryAxis = new NumericalAxis()
            {
                Minimum = 0, Maximum = 119, Interval = 20, RangePadding = NumericalPadding.None, LabelStyle = new ChartAxisLabelStyle()
                {
                    TextColor = Color.White
                }, IsInversed = false
            };

            chart.SecondaryAxis  = secondaryAxis;
            chart.PrimaryAxis    = primaryAxis;
            chart.BindingContext = Ot;
            BarSeries series2 = new BarSeries()
            {
                XBindingPath = "Description",
                YBindingPath = "WeightPercent"
            };

            series2.SetBinding(ChartSeries.ItemsSourceProperty, new Binding("CatsOverall"));
            series2.ColorModel        = ColorModel;
            series2.StrokeWidth       = 0.3;
            series2.EnableAnimation   = true;
            series2.AnimationDuration = 0.8;
            ChartDataMarker cDm = new ChartDataMarker();

            cDm.LabelTemplate = new DataTemplate(() =>
            {
                StackLayout layout = new StackLayout()
                {
                    Orientation = StackOrientation.Horizontal, Spacing = 0
                };
                Label l1 = new Label()
                {
                    TextColor = Color.White, FontSize = 10f
                };
                l1.SetBinding(Label.TextProperty, new Binding("WeightPercent", stringFormat: "{0}"));
                Label l2 = new Label()
                {
                    TextColor = Color.White, FontSize = 10f
                };
                l2.SetBinding(Label.TextProperty, new Binding("Weight", stringFormat: "/{0}"));
                layout.Children.Add(l1);
                layout.Children.Add(l2);
                return(layout);
            });
            cDm.LabelStyle.TextColor = Color.White;
            series2.DataMarker       = cDm;

            BarSeries series1 = new BarSeries()
            {
                XBindingPath = "Description",
                YBindingPath = "Weight",
            };

            series1.SetBinding(ChartSeries.ItemsSourceProperty, new Binding("CatsOverall"));
            series1.StrokeColor       = Color.White;
            series1.StrokeWidth       = 0.3;
            series1.EnableAnimation   = true;
            series1.AnimationDuration = 0.8;
            series1.Color             = Color.Transparent;

            series1.ListenPropertyChange = true;
            series2.ListenPropertyChange = true;

            chart.Series.Add(series2);
            chart.Series.Add(series1);

            chart.PrimaryAxis.ShowMajorGridLines   = false;
            chart.SecondaryAxis.ShowMajorGridLines = false;
            chart.SecondaryAxis.ShowMinorGridLines = false;

            Holder.Children.Add(chart);
            CategoryHolder.Children.Add(Holder);
        }