public async Task <BikeColorsGraphModel> GenerateColors() { BikeColorsGraphModel bcgm = new BikeColorsGraphModel(); BikeTheftViewModel bvm = new BikeTheftViewModel(); await bvm.GetBikeTheftsAsync(); foreach (var color in bvm.colors) { Color colorObject = new Color(); colorObject.Name = color; colors.Add(colorObject); } foreach (BikeTheft bikeTheft in bvm.BikeThefts) { Color color = colors.Find(x => x.Name.Contains(bikeTheft.Color)); color.AddColor(bikeTheft.Color); } var filteredColors = colors.OrderByDescending(x => x.Count).Take(9); int Count = 0; foreach (Color color in filteredColors) { Count += color.Count; bcgm.AddData(color); } Color remainderColor = new Color(); remainderColor.Name = "Remainder colors"; for (int i = 0; i < bvm.BikeThefts.Count() - Count; i++) { remainderColor.AddColor("Reminder"); } bcgm.AddData(remainderColor); return(bcgm); }
public async void GenerateGraph() { BrandColorGenerator generator = new BrandColorGenerator(); BikeColorsGraphModel bg = await generator.GenerateColors(); colorChart.Legend = new ChartLegend(); colorChart.Legend.Title.Text = "Most stolen colours (Swipe left-to-right for brands)"; colorChart.Series.Add(new PieSeries() { ItemsSource = bg.model, XBindingPath = "Name", YBindingPath = "Count", EnableTooltip = true, EnableAnimation = true, AnimationDuration = 3, EnableSmartLabels = true }); }