public static ResultContrast ShowEnergyAnalyseLineChart(QueryAnalyse queryAnalyse, string[] chartObject, string[] chartDept, Dictionary <string, List <decimal> > dir) { //表格数据定义 List <EnergyContrst> enerList = new List <EnergyContrst>(); ResultContrast contrast = new ResultContrast(); ExecuteProcess execu = new ExecuteProcess(); if (chartObject.Length == 0) { execu.Success = false; execu.ExceptionMsg = "暂无数据信息"; execu.ActionName = ""; execu.ActionUser = ""; execu.ActionTime = System.DateTime.Now; } else { execu.Success = true; execu.ExceptionMsg = ""; } string sql = " and ItemCodeNumber = '" + queryAnalyse.ItemCode + "'"; List <NTS.WEB.Model.Itemcode> itemList = Framework.Common.BaseWcf.CreateChannel <ServiceInterface.IEnergyContrastService>("EnergyContrastService") .GetItemCodeList(sql, ""); contrast.ActionInfo = execu; #region 数据series LineJson lineJson = new LineJson(); List <EneryCompare> compareList = new List <EneryCompare>(); #endregion int Index = 0; StringBuilder chartNew = new StringBuilder(); { foreach (var d in dir) { EnergyContrst ener = new EnergyContrst(); EneryCompare compareItem = new EneryCompare(); if (itemList.Count == 0) { ener.EneType = "总能耗"; } else { ener.EneType = itemList[0].ItemCodeName; } ener.Obj = d.Key; ener.Tm = queryAnalyse.StartTime.ToString(); ener.Val = Math.Round(d.Value.Sum(), 2); compareItem.name = d.Key; compareItem.data = d.Value; compareList.Add(compareItem); enerList.Add(ener); Index++; } if (chartDept.Length > 0) { lineJson.Unit = chartDept[0]; contrast.Unit = chartDept[0]; } lineJson.CompareType = "object"; contrast.ContrastLst = enerList; // 表格数据。 lineJson.series = compareList; contrast.lineJson = lineJson; //lineJson.series = return(contrast); } }
public IHttpActionResult Post([FromBody] string data) { GrafJson json = JsonConvert.DeserializeObject <GrafJson>(data); int gebruiker = int.Parse(User.Identity.GetUserId()); switch (json.type) { case "line": LineJson line = JsonConvert.DeserializeObject <LineJson>(data); line.ToString(); List <Serie> series = new List <Serie>(); Grafiek grafiek = new Lijn(grafiekenMng.NewGrafiek().ID, line.title, new As() { Titel = "Aantal Tweets", IsUsed = true }, series); grafiek.GebruikerId = gebruiker; grafiek.PlotOptions.PointStart = line.pointStart.ToString(); foreach (PersoonJson persoon in line.series) { AantalBerichtenPerWeekModel model = GetAantalBerichtenPerWeekModel(line.aantalWeken, int.Parse(persoon.id)); Serie serie = new Serie(); serie.Naam = persoon.naam; foreach (int d in model.Data) { Data dat = new Data(d); serie.Data.Add(dat); } grafiek.Series.Add(serie); } grafiekenMng.AddGrafiek(grafiek); break; case "bar": BarJson bar = JsonConvert.DeserializeObject <BarJson>(data); bar.ToString(); As xAs = new As() { IsUsed = true }; As yAs = new As() { IsUsed = true, Titel = "Aantal Tweets" }; List <Categorie> categories = new List <Categorie>(); foreach (string categorie in bar.categories) { categories.Add(new Categorie(categorie)); } xAs.Categorieen = categories; List <Serie> series2 = new List <Serie>(); foreach (PersoonJson persoon in bar.series) { int id = int.Parse(persoon.id); int aantal = berichtMng.GetBerichten(b => b.Personen.FirstOrDefault(p => p.ID == id) != null).ToList().Count; Serie serie = new Serie(); serie.Naam = berichtMng.GetPersoon(id).Naam; serie.Data.Add(new Data(aantal)); series2.Add(serie); } Grafiek grafiek2 = new Bar(grafiekenMng.NewGrafiek().ID, bar.title, xAs, series2 ); grafiek2.yAs = yAs; grafiek2.GebruikerId = gebruiker; grafiekenMng.AddGrafiek(grafiek2); break; case "pie": PieJson pie = JsonConvert.DeserializeObject <PieJson>(data); pie.ToString(); Serie serie2 = new Serie(); serie2.Naam = pie.serieNaam; for (int i = 0; i < pie.series.Count; i++) { Data data2 = new Data() { Naam = pie.series[i].naam, Value = pie.waarden[i] }; serie2.Data.Add(data2); } Grafiek grafiek3 = new Pie(grafiekenMng.NewGrafiek().ID, pie.title, serie2); grafiek3.GebruikerId = gebruiker; grafiekenMng.AddGrafiek(grafiek3); break; } return(Ok()); }