private void BuildBody(Dictionary <int, Dictionary <string, CirclePoint> > data) { var counter = default(int); foreach (var step in data) { PieDataCollection <PieSegment> collection = new PieDataCollection <PieSegment>(); collection.CollectionName = $"Ранжування {step.Key}"; bool flag = false; foreach (var element in step.Value) { var name = string.Empty; if (element.Key.Length >= 15) { name = element.Key.Substring(0, 15) + "..."; } else { name = element.Key; } if (element.Key == this.Title) { collection.Add(new PieSegment() { Color = Colors.Orange, Name = name, Value = element.Value.distance, }); } else { if (flag == true) { collection.Add(new PieSegment() { Color = Colors.Violet, Name = name, Value = element.Value.distance, }); } else { collection.Add(new PieSegment() { Color = Colors.DarkViolet, Name = name, Value = element.Value.distance, }); } flag = true; } } _collectionList.Add(collection); PieChart pie = new PieChart() { Width = 400, Height = 200, PieWidth = 190, PieHeight = 190, Margin = new Thickness(5, 5, 5, 5), HorizontalAlignment = HorizontalAlignment.Left, Data = collection, PopupBrush = new SolidColorBrush(Colors.White), }; pie.SetValue(Grid.ColumnProperty, counter); pie.SetValue(Grid.RowProperty, 1); Charts.Children.Add(pie); Label info = new Label(); info.Content = $"Ранжування {step.Key}"; info.VerticalAlignment = VerticalAlignment.Top; info.Margin = new Thickness(counter * 400 + 150, 0, 0, 0); info.Foreground = new SolidColorBrush(new Color() { A = 100, R = 93, G = 191, B = 56 }); info.FontSize = 14; info.FontWeight = FontWeights.Bold; Base.Children.Add(info); counter++; } }
private void DrawCharts() { var counter = default(int); PieDataCollection <PieSegment> collection = new PieDataCollection <PieSegment>(); _collectionList = new PieDataCollection <PieSegment>(); PieChart pie = new PieChart() { Width = 600, Height = 500, PieWidth = 450, PieHeight = 450, Margin = new Thickness(5, 5, 5, 5), HorizontalAlignment = HorizontalAlignment.Left, Data = collection, PopupBrush = new SolidColorBrush(Colors.White), }; pie.SetValue(Grid.ColumnProperty, 0); pie.SetValue(Grid.RowProperty, counter++); var storage = new Dictionary <string, double>(); foreach (var step in Data) { foreach (var item in step.Value) { if (!storage.ContainsKey(item.Key)) { storage.Add(item.Key, item.Value.distance); } else { storage[item.Key] += item.Value.distance; } } } var sortedStorage = storage.OrderBy(x => x.Value).Reverse(); foreach (var item in sortedStorage) { collection.Add(new PieSegment() { Color = new System.Windows.Media.Color() { A = 100, R = (byte)SoulData.ColorStorage[item.Key].Item1, G = (byte)SoulData.ColorStorage[item.Key].Item2, B = (byte)SoulData.ColorStorage[item.Key].Item3, }, Name = item.Key, Value = item.Value, } ); } pie.Data = collection; Charts.Children.Add(pie); _collectionList = collection; }