Exemple #1
0
        public async Task <BikeBrandsGraphModel> GenerateBrands()
        {
            BikeBrandsGraphModel bbgm = new BikeBrandsGraphModel();

            BikeTheftViewModel bvm = new BikeTheftViewModel();
            await bvm.GetBikeTheftsAsync();

            foreach (var brand in bvm.brands)
            {
                Brand brandObject = new Brand();
                brandObject.Name = brand;
                brands.Add(brandObject);
            }

            foreach (BikeTheft bikeTheft in bvm.BikeThefts)
            {
                Brand brand = brands.Find(x => x.Name.Contains(bikeTheft.Brand));
                brand.AddColor(bikeTheft.Brand);
            }

            var filteredBrands = brands.OrderByDescending(x => x.Count).Take(9);

            var Count = 0;

            foreach (Brand brand in filteredBrands)
            {
                Count += brand.Count;
                bbgm.AddData(brand);
            }

            Brand remainderBrand = new Brand();

            remainderBrand.Name = "Remainder brand";
            for (int i = 0; i < bvm.BikeThefts.Count() - Count; i++)
            {
                remainderBrand.AddColor("Reminder");
            }

            bbgm.AddData(remainderBrand);


            return(bbgm);
        }
Exemple #2
0
        public async void GenerateGraph()
        {
            BrandColorGenerator generator = new BrandColorGenerator();

            BikeBrandsGraphModel bg = await generator.GenerateBrands();

            brandChart.Legend            = new ChartLegend();
            brandChart.Legend.Title.Text = "Most stolen brands (Swipe right-to-left to see colours)";


            brandChart.Series.Add(new PieSeries()
            {
                ItemsSource       = bg.model,
                XBindingPath      = "Name",
                YBindingPath      = "Count",
                EnableTooltip     = true,
                EnableAnimation   = true,
                AnimationDuration = 3,
                EnableSmartLabels = true
            });
        }