操作Datatable group by 查询
//获取统计图形数据 var dicleft = new Dictionary<string, DataTable>(); var query = from t in dataTableList[0].AsEnumerable() group t by new { mname = t.Field<string>("COL_MATERIAL_NAME") } into m select new { MaterialName = m.Key.mname, value = m.ToList() }; foreach (var item in query) { var dtmax = new DataTable(); dtmax.Columns.Add("XValue"); dtmax.Columns.Add("YValue"); var dtmin = dtmax.Copy(); var dtavg = dtmax.Copy(); var dtup = dtmax.Copy(); var dtdown = dtmax.Copy(); foreach (DataRow dritem in item.value) { DataRow dr = dtmax.NewRow(); dr["XValue"] = dritem["COL_DATEMONTH"]; dr["YValue"] = dritem["COL_MAXVALUE"]; dtmax.Rows.Add(dr); dr = dtmin.NewRow(); dr["XValue"] = dritem["COL_DATEMONTH"]; dr["YValue"] = dritem["COL_MINVALUE"]; dtmin.Rows.Add(dr); dr = dtavg.NewRow(); dr["XValue"] = dritem["COL_DATEMONTH"]; dr["YValue"] = dritem["COL_AVGVALUE"]; dtavg.Rows.Add(dr); dr = dtup.NewRow(); dr["XValue"] = dritem["COL_DATEMONTH"]; dr["YValue"] = dritem["COL_UPVALUE"]; dtup.Rows.Add(dr); dr = dtdown.NewRow(); dr["XValue"] = dritem["COL_DATEMONTH"]; dr["YValue"] = dritem["COL_DOWNVALUE"]; dtdown.Rows.Add(dr); } dicleft.Add(item.MaterialName + "-最高值", dtmax); dicleft.Add(item.MaterialName + "-最低值", dtmin); dicleft.Add(item.MaterialName + "-平均值", dtavg); dicleft.Add(item.MaterialName + "-内控上限", dtup); dicleft.Add(item.MaterialName + "-内控下限", dtdown); } chartEntity = QMBasicData.AnalyticSeriesData(dicleft, "", new Dictionary<string, DataTable>(), "", ChartTypeEnum.Line);