コード例 #1
0
        public CustomerCategorySalesChartView()
        {
            #region chart series
            PieSeries pieSeries = new PieSeries()
            {
                ExplodeAll         = true,
                ConnectorLineType  = ConnectorLineType.Bezier,
                DataMarkerPosition = CircularSeriesDataMarkerPosition.OutsideExtended,
                DataMarker         = new ChartDataMarker()
                {
                    LabelStyle = new DataMarkerLabelStyle()
                    {
                        Margin      = new Thickness(5),
                        LabelFormat = "$0.00"
                    }
                },
                ColorModel = new ChartColorModel()
                {
                    Palette       = ChartColorPalette.Custom,
                    CustomBrushes = new List <Color>()
                    {
                        Palette._014,
                        Palette._015,
                        Palette._016
                    }
                }
            };

            pieSeries.SetBinding(ChartSeries.ItemsSourceProperty, "CategorySalesChartDataPoints");
            #endregion

            #region chart
            SfChart chart = new SfChart()
            {
                HeightRequest = ChartHeight,
                Legend        = new ChartLegend()
                {
                    DockPosition = LegendPlacement.Top
                },
                //BackgroundColor = Color.Transparent
            };
            chart.Legend.LabelStyle.TextColor = LegendLabelColor;

            chart.SetBinding(IsEnabledProperty, "IsBusy", converter: new InverseBooleanConverter());
            chart.SetBinding(IsVisibleProperty, "IsBusy", converter: new InverseBooleanConverter());

            chart.Series.Add(pieSeries);
            #endregion

            #region platform adjustments
            Device.OnPlatform(
                Android: () =>
            {
                Font androidChartLabelFont           = Font.SystemFontOfSize(Device.GetNamedSize(NamedSize.Large, typeof(Label)) * 1.5);
                pieSeries.DataMarker.LabelStyle.Font = androidChartLabelFont;
            });
            #endregion

            Content = chart;
        }
コード例 #2
0
        private void btnGrabar_Clicked(object sender, EventArgs e)
        {
            var series = new PieSeries();

            series.SetBinding(PieSeries.ItemsSourceProperty, new Binding("Data"));
            series.ValueBinding = new PropertyNameDataPointBinding("Value");
            chart.Series.Add(series);
            try
            {
                SendData(DateTime.Now.ToString(), DateTime.Now.Minute.ToString());
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
コード例 #3
0
        private void AddFileToChart(FileItemViewModel viewModel)
        {
            var mapper = new PieMapper <FileItemViewModel>().Value(f => f.Megabytes);
            var series = new PieSeries(mapper);

            series.Title      = viewModel.Name;
            series.Visibility = viewModel.ChartVisibility;
            series.Values     = new ChartValues <FileItemViewModel>()
            {
                viewModel
            };
            series.DataContext = viewModel;
            series.SetBinding(PieSeries.VisibilityProperty, FileItemViewModel.ChartVisibilityPropertyName);
            this.PieChart.Series.Add(series);

            foreach (var child in viewModel.Children)
            {
                this.AddFileToChart(child);
            }
        }
コード例 #4
0
        private static PieSeries ProvidePieSeries(PropertyInfo propertyInfo, string dependentValuePath,
                                                  string independentValuePath)
        {
            var series = new PieSeries();

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

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

                BindingOperations.ClearAllBindings(control);
            };

            return(series);
        }
コード例 #5
0
        private View CreateChart()
        {
            var container = new StackLayout();

            // >> chart-features-piechart-legend-definition-cs
            var chart = new RadPieChart
            {
                BindingContext = new ViewModel(),
                HeightRequest  = 300
            };
            // >> chart-features-piechart-legendtitlebinding-cs
            var series = new PieSeries
            {
                ValueBinding       = new PropertyNameDataPointBinding("Value"),
                DisplayName        = "Value",
                LegendTitleBinding = new PropertyNameDataPointBinding("Category")
            };

            // << chart-features-piechart-legendtitlebinding-cs
            series.SetBinding(ChartSeries.ItemsSourceProperty, new Binding("Data1"));
            chart.Series.Add(series);

            var legend = new RadLegend
            {
                LegendProvider      = chart,
                HeightRequest       = 200,
                LegendItemFontColor = Color.DarkGreen,
                LegendItemFontSize  = 20
            };

            // << chart-features-piechart-legend-definition-cs

            container.Children.Add(chart);
            container.Children.Add(legend);

            return(container);
        }
コード例 #6
0
        private void GenPieChart(Dictionary <string, int> pieChartData)
        {
            PART_PieChartControl.Series.Clear();
            var sum = pieChartData.Values.Sum();

            var pointLabelBinding = new Binding(nameof(PointLabel))
            {
                Source = this
            };

            foreach (var key in pieChartData.Keys)
            {
                // Calculate proportion
                var proportion     = pieChartData[key] / (double)sum;
                var proportionText = $"{proportion * 100 :F1}%";

                var series = new PieSeries()
                {
                    Title = key, Values = new ChartValues <int>(new[] { pieChartData[key] }), ToolTip = proportionText, DataLabels = true
                };
                series.SetBinding(PointLabelProperty, pointLabelBinding);
                PART_PieChartControl.Series.Add(series);
            }
        }