public static FlotPie GetBrowserStats(IStatsRepository repository) { var browsers = repository.FetchBrowserStats().ToList(); var chart = new FlotPie(); var browserList = browsers.Select(b => b.BrowserName).Distinct().ToDictionary(browser => browser, chart.AddSeries); foreach (var kvp in browserList) { chart.SetData(kvp.Value, browsers.Where(b => b.BrowserName == kvp.Key).Sum(v => v.Count.HasValue ? v.Count.Value : 0)); } return(chart); }