Exemplo n.º 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;
        }
        public DiaryDashboardChartView()
        {
            var chartHeaderView = new DiaryChartHeaderView()
            {
                HeightRequest = RowSizes.MediumRowHeightDouble, Padding = new Thickness(20, 10, 20, 0)
            };

            chartHeaderView.SetBinding(DiaryChartHeaderView.WeeklyAverageProperty, "AverageWeeklyCalories");

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

            #region activity indicator
            var chartActivityIndicator = new ActivityIndicator()
            {
                HeightRequest = RowSizes.MediumRowHeightDouble
            };

            chartActivityIndicator.SetBinding(IsEnabledProperty, "IsBusy");
            chartActivityIndicator.SetBinding(IsVisibleProperty, "IsBusy");
            chartActivityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsBusy");
            #endregion

            #region loading label
            Label loadingLabel = new Label()
            {
                Text                    = TextResources.DiaryDashboard_FoodChart_LoadingLabel,
                FontSize                = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
                HeightRequest           = RowSizes.MediumRowHeightDouble,
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment   = TextAlignment.End,
                TextColor               = Palette._007
            };

            loadingLabel.SetBinding(IsEnabledProperty, "IsBusy");
            loadingLabel.SetBinding(IsVisibleProperty, "IsBusy");
            #endregion

            #region Calories Graph

            double chartHeight  = Device.OnPlatform(190, 250, 190);
            var    columnSeries = new ColumnSeries()
            {
                YAxis = new NumericalAxis()
                {
                    Title = new ChartAxisTitle()
                    {
                        Text      = TextResources.DiaryDashboard_FoodChart_YAxis_Title,
                        Font      = ChartAxisFont,
                        TextColor = Palette._011
                    },
                    OpposedPosition    = false,
                    ShowMajorGridLines = true,
                    MajorGridLineStyle = new ChartLineStyle()
                    {
                        StrokeColor = AxisLineColor
                    },
                    ShowMinorGridLines    = true,
                    MinorTicksPerInterval = 1,
                    MinorGridLineStyle    = new ChartLineStyle()
                    {
                        StrokeColor = AxisLineColor
                    },
                    LabelStyle = new ChartAxisLabelStyle()
                    {
                        TextColor = AxisLabelColor
                    }
                },
                DataMarker = new ChartDataMarker()
                {
                    LabelStyle = new DataMarkerLabelStyle()
                    {
                        LabelPosition   = DataMarkerLabelPosition.Auto,
                        TextColor       = Palette._001,
                        BackgroundColor = Color.Transparent
                    }
                },
                DataMarkerPosition       = DataMarkerPosition.Top,
                EnableDataPointSelection = false,
                Color = Palette._003
            };


            // Bind data points to the chart
            columnSeries.SetBinding(ChartSeries.ItemsSourceProperty, "WeeklyCaloriesChartDataPoints");


            var chart = new SfChart()
            {
                HeightRequest = chartHeight,

                PrimaryAxis = new CategoryAxis()
                {
                    Title = new ChartAxisTitle()
                    {
                        Text      = TextResources.DiaryDashboard_FoodChart_PrimaryAxis_Title,
                        Font      = ChartAxisFont,
                        TextColor = Palette._011
                    },

                    LabelRotationAngle    = -45,
                    EdgeLabelsDrawingMode = EdgeLabelsDrawingMode.Center,
                    LabelPlacement        = LabelPlacement.BetweenTicks,
                    TickPosition          = AxisElementPosition.Inside,
                    ShowMajorGridLines    = false,
                    LabelStyle            = new ChartAxisLabelStyle()
                    {
                        TextColor = AxisLabelColor
                    }
                }
            };

            if (Device.OS == TargetPlatform.Android)
            {
                chart.BackgroundColor = Color.Transparent;
            }

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

            StackLayout stackLayout = new StackLayout()
            {
                Spacing  = 5,
                Children =
                {
                    loadingLabel,
                    chartActivityIndicator,
                    chartHeaderView,
                    new ContentView()
                    {
                        Content = chart,   HeightRequest= chartHeight
                    }
                }
            };
            #endregion


            #region platform adjustments
            Device.OnPlatform(
                iOS: () =>
            {
                columnSeries.DataMarker.LabelStyle.Font = Font.SystemFontOfSize(Device.GetNamedSize(NamedSize.Micro, typeof(Label)) * 0.6);
            },
                Android: () =>
            {
                // Controls Y Axis Data Points Labels
                columnSeries.YAxis.LabelStyle.Font = Font.SystemFontOfSize(Device.GetNamedSize(NamedSize.Micro, typeof(Label)) * 1.5);

                columnSeries.DataMarker.LabelStyle.Font = Font.SystemFontOfSize(Device.GetNamedSize(NamedSize.Micro, typeof(Label)) * 1.2);
                chart.PrimaryAxis.LabelStyle.Font       = Font.SystemFontOfSize(Device.GetNamedSize(NamedSize.Micro, typeof(Label)) * 1.5);
            });
            #endregion

            Content = stackLayout;
        }
Exemplo n.º 3
0
        public SalesDashboardChartView()
        {
            #region sales graph header
            SalesChartHeaderView chartHeaderView = new SalesChartHeaderView()
            {
                HeightRequest = Sizes.MediumRowHeight, Padding = new Thickness(20, 10, 20, 0)
            };
            chartHeaderView.WeeklyAverageValueLabel.SetBinding(Label.TextProperty, "WeeklySalesAverage");
            chartHeaderView.SetBinding(IsEnabledProperty, "IsBusy", converter: new InverseBooleanConverter());
            chartHeaderView.SetBinding(IsVisibleProperty, "IsBusy", converter: new InverseBooleanConverter());
            #endregion

            #region activity indicator
            ActivityIndicator chartActivityIndicator = new ActivityIndicator()
            {
                HeightRequest = Sizes.MediumRowHeight
            };
            chartActivityIndicator.SetBinding(IsEnabledProperty, "IsBusy");
            chartActivityIndicator.SetBinding(IsVisibleProperty, "IsBusy");
            chartActivityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsBusy");
            #endregion

            #region loading label
            Label loadingLabel = new Label()
            {
                Text          = TextResources.SalesDashboard_SalesChart_LoadingLabel,
                FontSize      = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
                HeightRequest = Sizes.MediumRowHeight,
                XAlign        = TextAlignment.Center,
                YAlign        = TextAlignment.End,
                TextColor     = Palette._007
            };
            loadingLabel.SetBinding(IsEnabledProperty, "IsBusy");
            loadingLabel.SetBinding(IsVisibleProperty, "IsBusy");
            #endregion

            #region the sales graph
            const double chartHeight = 190;

            ColumnSeries columnSeries = new ColumnSeries()
            {
                YAxis = new NumericalAxis()
                {
                    OpposedPosition    = false,
                    ShowMajorGridLines = true,
                    MajorGridLineStyle = new ChartLineStyle()
                    {
                        StrokeColor = MajorAxisAndLableColor
                    },
                    ShowMinorGridLines    = true,
                    MinorTicksPerInterval = 1,
                    MinorGridLineStyle    = new ChartLineStyle()
                    {
                        StrokeColor = MajorAxisAndLableColor
                    },
                    LabelStyle = new ChartAxisLabelStyle()
                    {
                        TextColor   = MajorAxisAndLableColor,
                        LabelFormat = "$0"
                    }
                },
                Color = Palette._003
            };

            columnSeries.SetBinding(ColumnSeries.ItemsSourceProperty, "WeeklySalesChartDataPoints");

            SfChart chart = new SfChart()
            {
                HeightRequest = chartHeight,

                PrimaryAxis = new CategoryAxis()
                {
                    EdgeLabelsDrawingMode = EdgeLabelsDrawingMode.Center,
                    LabelPlacement        = LabelPlacement.BetweenTicks,
                    TickPosition          = AxisElementPosition.Inside,
                    ShowMajorGridLines    = false,
                    LabelStyle            = new ChartAxisLabelStyle()
                    {
                        TextColor = MajorAxisAndLableColor
                    }
                },

                BackgroundColor = Color.Transparent
            };

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

            // The chart has uncontrollable white space on it's left in iOS, so we're
            // wrapping it in a ContentView and adding some right padding to compensate.
            ContentView chartWrapper = new ContentView()
            {
                Content = chart
            };

            StackLayout stackLayout = new UnspacedStackLayout()
            {
                Children =
                {
                    chartHeaderView,
                    loadingLabel,
                    chartActivityIndicator,
                    chartWrapper
                }
            };
            #endregion

            #region platform adjustments
            Device.OnPlatform(
                iOS: () =>
            {
                chartWrapper.Padding        = new Thickness(0, 0, 30, 0);
                stackLayout.BackgroundColor = Color.Transparent;
                stackLayout.Padding         = new Thickness(0, 20, 0, 0);
            },
                Android: () =>
            {
                stackLayout.BackgroundColor        = Palette._009;
                Font androidChartLabelFont         = Font.SystemFontOfSize(Device.GetNamedSize(NamedSize.Large, typeof(Label)) * 1.5);
                columnSeries.YAxis.LabelStyle.Font = androidChartLabelFont;
                chart.PrimaryAxis.LabelStyle.Font  = androidChartLabelFont;
            });
            #endregion

            Content = stackLayout;
        }