private IEnumerable <ResourceModel> PackData(IEnumerable <ResourceModel> Data, int width) { var data = Data.OrderBy(x => x.Date); var cnt = data.Count(); var idx = 0; var perPixel = Math.Max(1, cnt / width * 4); if (perPixel == 1) { return(data); } var list = new List <ResourceModel>(); var tmp = new ResourceModel(); foreach (var model in data) { tmp += model; idx = (idx + 1) % perPixel; if (idx == 0) { list.Add(tmp / perPixel); tmp.Clear(); } } if (idx > 0) { list.Add(tmp / idx); } return(list.ToArray()); }