public void chartBarras(SfChart chart, string xpath, string ypath, string unids, string title)
        {
            chart.Title.Text = title;
            chart.Legend     = new ChartLegend();
            CategoryAxis primaryAxis = new CategoryAxis();

            primaryAxis.Title.Text = xpath;
            chart.PrimaryAxis      = primaryAxis;

            NumericalAxis secondaryAxis = new NumericalAxis();

            secondaryAxis.Title.Text = ypath + " ( " + unids + " ) ";
            chart.SecondaryAxis      = secondaryAxis;

            ColumnSeries series = new ColumnSeries();

            series.SetBinding(ChartSeries.ItemsSourceProperty, "Data");
            series.XBindingPath      = xpath;
            series.YBindingPath      = ypath;
            series.EnableAnimation   = true;
            series.AnimationDuration = 0.9;
            series.EnableTooltip     = true;
            chart.Series.Add(series);
            charts.Add(chart);
        }
Beispiel #2
0
        public void InicializarChart1()
        {
            chart1            = new SfChart();
            chart1.Title.Text = "Infracciones por Dispositivo";

            CategoryAxis primaryAxis = new CategoryAxis();

            primaryAxis.Title.Text = "Direccion";
            chart1.PrimaryAxis     = primaryAxis;

            NumericalAxis secondaryAxis = new NumericalAxis();

            secondaryAxis.Title.Text = "Infracciones (unidades)";
            chart1.SecondaryAxis     = secondaryAxis;

            ColumnSeries series  = new ColumnSeries();
            ColumnSeries series2 = new ColumnSeries();

            series.SetBinding(ChartSeries.ItemsSourceProperty, "DataHombres");
            series2.SetBinding(ChartSeries.ItemsSourceProperty, "DataMujeres");

            series.XBindingPath             = "Direccione";
            series.YBindingPath             = "Infracciones";
            series.EnableAnimation          = true;
            series.AnimationDuration        = 0.9;
            series.EnableTooltip            = true;
            series.EnableDataPointSelection = true;
            series.Label      = "Hombres";
            series.DataMarker = new ChartDataMarker();

            series2.XBindingPath             = "Direccione";
            series2.YBindingPath             = "Infracciones";
            series2.EnableAnimation          = true;
            series2.AnimationDuration        = 0.9;
            series2.EnableTooltip            = true;
            series2.EnableDataPointSelection = true;
            series2.Label      = "Mujeres";
            series2.DataMarker = new ChartDataMarker();

            chart1.Legend = new ChartLegend();
            chart1.Series.Add(series);
            chart1.Series.Add(series2);

            chart1.Legend.ToggleSeriesVisibility = true;
            chart1.Margin = new Thickness(5, 6, 5, 5);

            chart1.VerticalOptions      = LayoutOptions.FillAndExpand;
            chart1.MinimumHeightRequest = 350;
            chart1.HeightRequest        = 350;
        }
        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;
        }
Beispiel #4
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;
        }
Beispiel #5
0
        private SfChart PrefChart(int type)
        {
            if (type == 1)
            {
                SfChart chart = new SfChart()
                {
                    SideBySideSeriesPlacement = false, HeightRequest = 370, BackgroundColor = Color.Transparent
                };

                Binding chartBind1 = new Binding("CatInfoSet");
                chartBind1.Converter          = new BarChartConverter();
                chartBind1.ConverterParameter = 1;

                ColumnSeries series1 = new ColumnSeries();
                series1.SetBinding(ChartSeries.ItemsSourceProperty, new Binding("CatInfoSet"));
                series1.XBindingPath = "Description";
                series1.YBindingPath = "Weight";
                series1.SetBinding(ColumnSeries.WidthProperty, chartBind1);
                series1.Color       = Xamarin.Forms.Color.Transparent;
                series1.StrokeColor = Color.White;

                series1.CornerRadius      = new ChartCornerRadius(10, 10, 0, 0);
                series1.StrokeWidth       = 0.3;
                series1.EnableAnimation   = false;
                series1.AnimationDuration = 0.8;
                series1.DataMarker        = new ChartDataMarker();
                DataTemplate dataMarkerTemplate2 = new DataTemplate(() =>
                {
                    StackLayout stack = new StackLayout()
                    {
                        Spacing = 0
                    };
                    stack.Orientation = StackOrientation.Horizontal;
                    Label label1      = new Label()
                    {
                        TextColor = Color.White, FontSize = 12, VerticalOptions = LayoutOptions.Center
                    };
                    label1.SetBinding(Label.TextProperty, "WeightPercent");
                    Label label2 = new Label()
                    {
                        TextColor = Color.White, FontSize = 12, VerticalOptions = LayoutOptions.Center
                    };
                    label2.SetBinding(Label.TextProperty, "Weight", stringFormat: "/{0}");
                    stack.Children.Add(label1);
                    stack.Children.Add(label2);
                    return(stack);
                });
                series1.DataMarker.LabelTemplate = dataMarkerTemplate2;

                Binding chartBind2 = new Binding("CatInfoSet");
                chartBind2.Converter          = new BarChartConverter();
                chartBind2.ConverterParameter = 1;

                ColumnSeries series2 = new ColumnSeries();
                series2.SetBinding(ChartSeries.ItemsSourceProperty, new Binding("CatInfoSet"));
                series2.XBindingPath = "Description";
                series2.YBindingPath = "WeightPercent";

                series2.SetBinding(ColumnSeries.WidthProperty, chartBind2);

                series2.Opacity = 1;

                Binding backCol = new Binding("CatInfoSet");
                backCol.Converter          = new BarChartConverter();
                backCol.ConverterParameter = 4;

                series2.SetBinding(ChartSeries.ColorModelProperty, backCol);

                Binding labelOffsetBind = new Binding("CatInfoSet")
                {
                    Converter          = new BarChartConverter(),
                    ConverterParameter = 2
                };
                series2.EnableAnimation = true;
                series2.CornerRadius    = new ChartCornerRadius(10, 10, 0, 0);

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

                ChartZoomPanBehavior zoomPanBehavior = new ChartZoomPanBehavior();
                chart.ChartBehaviors.Add(zoomPanBehavior);
                zoomPanBehavior.EnableDirectionalZooming = true;

                NumericalAxis numericalAxis = new NumericalAxis()
                {
                    ShowMajorGridLines = true, ShowMinorGridLines = true, Minimum = 0, Maximum = 119, Name = "Score", Interval = 20, LabelStyle = new ChartAxisLabelStyle()
                    {
                        FontSize = 13, TextColor = Color.White, FontAttributes = FontAttributes.Bold
                    }
                };

                chart.SecondaryAxis = numericalAxis;
                chart.PrimaryAxis   = new CategoryAxis()
                {
                    Interval = 1, LabelPlacement = LabelPlacement.BetweenTicks, Name = "Prim"
                };

                chart.PrimaryAxis.LabelStyle.FontAttributes = FontAttributes.Bold;
                chart.PrimaryAxis.LabelStyle.FontSize       = 16;
                chart.SecondaryAxis.LabelStyle.FontSize     = 12;
                chart.PrimaryAxis.LabelStyle.TextColor      = Color.White;
                chart.PrimaryAxis.LabelsIntersectAction     = AxisLabelsIntersectAction.MultipleRows;

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

                return(chart);
            }
            else
            {
                SfChart chart = new SfChart()
                {
                    HeightRequest = 230, BackgroundColor = Xamarin.Forms.Color.FromRgba(0, 0, 0, 0), HorizontalOptions = LayoutOptions.Start
                };
                DoughnutSeries dSeries = new DoughnutSeries();
                dSeries.SetBinding(ChartSeries.ItemsSourceProperty, new Binding("CatInfoSet"));
                dSeries.XBindingPath      = "Description";
                dSeries.YBindingPath      = "Percent";
                dSeries.IsStackedDoughnut = true;
                dSeries.Spacing           = 0.6;
                Binding localBind = new Binding("CatInfoSet");
                localBind.Converter = new ListViewConverterItem();
                dSeries.SetBinding(DoughnutSeries.DoughnutCoefficientProperty, localBind);
                dSeries.MaximumValue    = 100;
                dSeries.CapStyle        = DoughnutCapStyle.BothCurve;
                dSeries.EnableAnimation = true;
                chart.Series.Add(dSeries);

                ChartLegend legend = new ChartLegend();
                chart.Legend = legend;
                chart.Legend.DockPosition         = LegendPlacement.Right;
                chart.Legend.Orientation          = ChartOrientation.Vertical;
                chart.Legend.LabelStyle.TextColor = Color.White;

                legend.ItemTemplate = new DataTemplate(() =>
                {
                    StackLayout stack = new StackLayout()
                    {
                        Orientation       = StackOrientation.Vertical,
                        HorizontalOptions = LayoutOptions.EndAndExpand,
                        Spacing           = 5,
                        VerticalOptions   = LayoutOptions.StartAndExpand
                    };

                    StackLayout SubStack = new StackLayout()
                    {
                        Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.StartAndExpand, WidthRequest = 200, Spacing = 2
                    };

                    BoxView boxView = new BoxView()
                    {
                        HorizontalOptions = LayoutOptions.Start,
                        VerticalOptions   = LayoutOptions.Center,
                        WidthRequest      = 15,
                        HeightRequest     = 15
                    };
                    boxView.SetBinding(BackgroundColorProperty, "IconColor");

                    Label name = new Label()
                    {
                        VerticalTextAlignment   = TextAlignment.Center,
                        HorizontalTextAlignment = TextAlignment.Start,
                        HorizontalOptions       = LayoutOptions.Center,
                        FontSize  = 13,
                        TextColor = Color.White
                    };
                    name.SetBinding(Label.TextProperty, "DataPoint.Description");

                    Frame frame = new Frame()
                    {
                        Padding = 1, Margin = 10, HeightRequest = 25, WidthRequest = 50, HorizontalOptions = LayoutOptions.EndAndExpand
                    };
                    Label value = new Label()
                    {
                        HorizontalOptions       = LayoutOptions.Center,
                        HorizontalTextAlignment = TextAlignment.Center,
                        VerticalTextAlignment   = TextAlignment.Center,
                        FontSize       = 14,
                        TextColor      = Color.White,
                        FontAttributes = FontAttributes.Bold,
                    };

                    Binding TextBind      = new Binding("DataPoint.Percent");
                    TextBind.Converter    = new LegendItemConverter();
                    TextBind.StringFormat = "{0}%";

                    value.SetBinding(Label.TextProperty, TextBind);
                    frame.Content = value;

                    Binding colorBind   = new Binding("DataPoint.Percent");
                    colorBind.Converter = new LegendItemConverter();
                    frame.SetBinding(BackgroundColorProperty, colorBind);

                    SubStack.Children.Add(boxView);
                    SubStack.Children.Add(name);
                    SubStack.Children.Add(frame);

                    stack.Children.Add(SubStack);
                    return(stack);
                });

                return(chart);
            }
        }