查询时已经按月份排序,但是柱状图是按柱添加上去,所以第一根柱没的5月和6月的数据,排序时就排到后面去了,现在我想让它按1-12月排序,该怎么写?
List<PurchaseStaticsist> lstPurchaseStaticsist = (from a in productionPurchaseOrderRepository.GetQuery(query_Order.Predicate)
join b in productionPurchaseDetailRepository.GetQuery(query.Predicate) on a.ProductionPurchaseOrderId equals b.ProductionPurchaseOrderId
where b.PurchaseStatus == "采购完成"
group b by new
{
//Year = SqlFunctions.DateName("year", b.LastUpdateTime),
//Month = SqlFunctions.DateName("month", b.LastUpdateTime),
Year = b.LastUpdateTime.Year,
Month = b.LastUpdateTime.Month,
a.PurchaseOrderType
} into g
select new
{
g.Key.Year,
Month=g.Key.Month,
g.Key.PurchaseOrderType,
TotalAmount = g.Sum(a => a.Money) / 10000,
}).Distinct().Where(a=>a.TotalAmount>0).OrderBy(a => a.Month).Select(a => new PurchaseStaticsist() { Year = a.Year.ToString(), Month = a.Month.ToString(), PurchaseOrderType = a.PurchaseOrderType, TotalAmount = a.TotalAmount }).ToList();
chartControl1.Series.Clear();
foreach (var item in parts_TypeRepository.GetQuery(a => a.RecordStatus))
{
// 柱状图里的第一个柱
Series Series1 = new Series(item.TypeName, ViewType.Bar);
Series1.DataSource = lstPurchaseStaticsist.Where(a => a.PurchaseOrderType == item.TypeName);
Series1.ArgumentScaleType = ScaleType.Qualitative;
// 以哪个字段进行显示
Series1.ArgumentDataMember = "Month";
Series1.ValueScaleType = ScaleType.Numerical;
// 柱状图里的柱的取值字段
Series1.ValueDataMembers.AddRange(new string[] { "TotalAmount" });
(Series1.Label as BarSeriesLabel).Position = BarSeriesLabelPosition.Top;
(Series1.Label as BarSeriesLabel).ResolveOverlappingMode = ResolveOverlappingMode.Default;
Series1.LabelsVisibility = DefaultBoolean.True;
chartControl1.Series.Add(Series1);
}
显然柱子的顺序是chartControl1.Series的元素顺序
那么就是parts_TypeRepository.GetQuery(a => a.RecordStatus)这个顺序不对
你就按照月份排序一下嘛
foreach (var item in parts_TypeRepository.GetQuery(a => a.RecordStatus).Orderby(t=>t.Month))