public DotNet.Highcharts.Highcharts set_graph(graphViewModel model) { DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts("chart") .SetTitle(new Title { Text = "Production Graph" }) .SetSubtitle(new Subtitle { Text = "Date : " + DateTime.Today, X = -20 }) .SetXAxis(new XAxis { Categories = new[] { "6am", "7am", "8am", "9am", "10am", "11am", "12pm", "1pm", "2pm", "3pm", "4pm", "5pm", "6pm" } }) .SetSeries(new[] { new Series { Name = "Laptop", Data = new Data(new object[] { model.laptop_six_am, model.laptop_six_am, model.laptop_seven_am, model.laptop_eight_am, model.laptop_nine_am, model.laptop_ten_am, model.laptop_eleven_am, model.laptop_twelve_pm, model.laptop_one_pm, model.laptop_two_pm, model.laptop_three_pm, model.laptop_four_pm, model.laptop_five_pm }) } , new Series { Name = "Desktop", Data = new Data(new object[] { model.desktop_six_am, model.desktop_six_am, model.desktop_seven_am, model.desktop_eight_am, model.desktop_nine_am, model.desktop_ten_am, model.desktop_eleven_am, model.desktop_twelve_pm, model.desktop_one_pm, model.desktop_two_pm, model.desktop_three_pm, model.desktop_four_pm, model.desktop_five_pm }) } } ); chart.InitChart(new Chart { Width = 800, Height = 250 }); return(chart); }
public DotNet.Highcharts.Highcharts discover_weekly_graph(graphViewModel model, List <DateTime> allDates) { Highcharts dis_weekly_chart = new Highcharts("dis_weekly_chart") .InitChart(new Chart { Width = 500, Height = 350, Type = ChartTypes.Column, Margin = new[] { 75 }, Options3d = new ChartOptions3d { Enabled = true, Alpha = 15, Beta = 15, Depth = 50, ViewDistance = 25 } }) .SetXAxis(new XAxis { Categories = new[] { allDates[0].ToString("yyyy-MM-dd"), allDates[1].ToString("yyyy-MM-dd"), allDates[2].ToString("yyyy-MM-dd"), allDates[3].ToString("yyyy-MM-dd"), allDates[4].ToString("yyyy-MM-dd"), allDates[5].ToString("yyyy-MM-dd"), allDates[6].ToString("yyyy-MM-dd") } }) .SetTitle(new Title { Text = "Discovery Weekly Graph" }) .SetPlotOptions(new PlotOptions { Column = new PlotOptionsColumn { Depth = 25 } }) .SetLegend(new Legend { Enabled = false }) .SetSeries(new Series { Data = new Data(new object[] { model.dis_day1, model.dis_day2, model.dis_day3, model.dis_day4, model.dis_day5, model.dis_day6, model.dis_day7 }) }); return(dis_weekly_chart); }
//get public ActionResult Index(graphViewModel model, string fromDate, string toDate) { var user = User.Identity; var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context)); var s = UserManager.GetRoles(user.GetUserId()); if (s[0].ToString() == "Employee") { return(RedirectToAction("Index_nonadmin", "Home")); } var dateCriteria = DateTime.Now.Date.AddDays(-7); //save all dates string into this array List <DateTime> allDates = new List <DateTime>(); for (DateTime date = dateCriteria; date <= DateTime.Now; date = date.AddDays(1)) { allDates.Add(date); } ViewBag.fromDate = fromDate; ViewBag.toDate = toDate; var coa_arr = (from m in db.coas where m.Recipient_Type != "USED" select m).ToArray(); var s1_windows = (from m in coa_arr where m.location == "wcoa_s1" select m).ToArray(); var s1_office = (from n in coa_arr where n.location == "ocoa_s1" select n).ToArray(); var s2_windows = (from m in coa_arr where m.location == "wcoa_s2" select m).ToArray(); var s2_office = (from n in coa_arr where n.location == "ocoa_s2" select n).ToArray(); int w_g360_count_s1 = 0; int w_ts_count_s1 = 0; int w_mar_count_s1 = 0; int o_g360_count_s1 = 0; int o_ts_count_s1 = 0; int o_mar_count_s1 = 0; int w_g360_count_s2 = 0; int w_ts_count_s2 = 0; int w_mar_count_s2 = 0; int o_g360_count_s2 = 0; int o_ts_count_s2 = 0; int o_mar_count_s2 = 0; foreach (var coa in s1_windows) { switch (coa.Recipient_Organization_Name) { case "Good360": w_g360_count_s1 += 1; break; case "TechSoup.org": w_ts_count_s1 += 1; break; case "Interconnection": w_mar_count_s1 += 1; break; } } foreach (var coa in s1_office) { switch (coa.Recipient_Organization_Name) { case "Good360": o_g360_count_s1 += 1; break; case "TechSoup.org": o_ts_count_s1 += 1; break; case "Interconnection": o_mar_count_s1 += 1; break; } } foreach (var coa2 in s2_windows) { switch (coa2.Recipient_Organization_Name) { case "Good360": w_g360_count_s2 += 1; break; case "TechSoup.org": w_ts_count_s2 += 1; break; case "Interconnection": w_mar_count_s2 += 1; break; } } foreach (var coa2 in s2_office) { switch (coa2.Recipient_Organization_Name) { case "Good360": o_g360_count_s2 += 1; break; case "TechSoup.org": o_ts_count_s2 += 1; break; case "Interconnection": o_mar_count_s2 += 1; break; } } ViewBag.w_g360_count_s1 = w_g360_count_s1; ViewBag.w_g360_count_s2 = w_g360_count_s2; ViewBag.o_g360_count_s1 = o_g360_count_s1; ViewBag.o_g360_count_s2 = o_g360_count_s2; ViewBag.w_ts_count_s1 = w_ts_count_s1; ViewBag.w_ts_count_s2 = w_ts_count_s2; ViewBag.o_ts_count_s1 = o_ts_count_s1; ViewBag.o_ts_count_s2 = o_ts_count_s2; ViewBag.w_mar_count_s1 = w_mar_count_s1; ViewBag.w_mar_count_s2 = w_mar_count_s2; ViewBag.o_mar_count_s1 = o_mar_count_s1; ViewBag.o_mar_count_s2 = o_mar_count_s2; if (ViewBag.fromDate != null) { DateTime end; DateTime begin = DateTime.Parse(fromDate); if (toDate == "") { end = begin.AddDays(1).AddTicks(-1); } else { end = DateTime.Parse(toDate); } var fromandto = (from m in db.production_log where m.time > begin && m.time < end && m.location.Contains("Station 1") select m.time).ToArray(); var fromandto2 = (from m in db.production_log where m.time > begin && m.time < end && m.location.Contains("Station 2") select m.time).ToArray(); process_array(fromandto, fromandto2, model, allDates); int count_stations = fromandto.Count() + fromandto2.Count(); ViewBag.fromandto_total = "[" + count_stations + "] Station 1: [" + fromandto.Count() + "] Station 2: [" + fromandto2.Count() + "]"; ViewBag.station1 = fromandto.Count(); ViewBag.station2 = fromandto2.Count(); ViewBag.total = count_stations; } else { DateTime startDateTime = DateTime.Today; //Today at 00:00:00 DateTime endDateTime = DateTime.Today.AddDays(1).AddTicks(-1); var pallet = (from t in db.production_log where (t.time >= startDateTime && t.time <= endDateTime) && t.location.Contains("Station 2") select t.time).ToArray(); //int result = pallet.Count(); var pallet2 = (from t in db.production_log where (t.time >= startDateTime && t.time <= endDateTime) && t.location.Contains("Station 1") select t.time).ToArray(); process_array(pallet2, pallet, model, allDates); ViewBag.today_total = "Station 1: [" + pallet2.Count() + "] Station 2: [" + pallet.Count() + "]"; ViewBag.station1 = pallet2.Count(); ViewBag.station2 = pallet.Count(); ViewBag.total = pallet.Count() + pallet2.Count(); } Highcharts discovery_data = discover_weekly_graph(model, allDates); Highcharts chartColumn = lastweek_graph(model, allDates); ChartsModel charts = new ChartsModel(); charts.Chart3 = chartColumn; charts.Chart2 = discovery_data; ViewBag.weekGrahp = lastweek_graph(model, allDates); ViewBag.dis_weekGrahp = discover_weekly_graph(model, allDates); ViewBag.Model = set_graph(model); return(View(charts)); // return View(); }
public void process_array(DateTime[] t, DateTime[] t2, graphViewModel model, List <DateTime> allDates) { //station 1 foreach (var time in t) { switch (time.ToString("%h")) { case "6": model.laptop_six_am += 1; break; case "7": model.laptop_seven_am += 1; break; case "8": model.laptop_eight_am += 1; break; case "9": model.laptop_nine_am += 1; break; case "10": model.laptop_ten_am += 1; break; case "11": model.laptop_eleven_am += 1; break; case "12": model.laptop_twelve_pm += 1; break; case "13": model.laptop_one_pm += 1; break; case "14": model.laptop_two_pm += 1; break; case "15": model.laptop_three_pm += 1; break; case "16": model.laptop_four_pm += 1; break; case "17": model.laptop_five_pm += 1; break; } } //stations 2 foreach (var time in t2) { switch (time.ToString("%h")) { case "6": model.desktop_six_am += 1; break; case "7": model.desktop_seven_am += 1; break; case "8": model.desktop_eight_am += 1; break; case "9": model.desktop_nine_am += 1; break; case "10": model.desktop_ten_am += 1; break; case "11": model.desktop_eleven_am += 1; break; case "12": model.desktop_twelve_pm += 1; break; case "13": model.desktop_one_pm += 1; break; case "14": model.desktop_two_pm += 1; break; case "15": model.desktop_three_pm += 1; break; case "16": model.desktop_four_pm += 1; break; case "17": model.desktop_five_pm += 1; break; } } //for pass 7 days var dateCriteria = DateTime.Now.Date.AddDays(-7); //start the query var lastweek = (from lastt in db.production_log where (lastt.time >= dateCriteria) select lastt.time).ToArray(); foreach (var d in lastweek) { if (d.Date == allDates[0]) { model.day1 += 1; } else if (d.Date == allDates[1]) { model.day2 += 1; } else if (d.Date == allDates[2]) { model.day3 += 1; } else if (d.Date == allDates[3]) { model.day4 += 1; } else if (d.Date == allDates[4]) { model.day5 += 1; } else if (d.Date == allDates[5]) { model.day6 += 1; } else if (d.Date == allDates[6]) { model.day7 += 1; } else if (d.Date == allDates[7]) { model.day8 += 1; } } var dis_lastweek = (from lastt in db.discovery where (lastt.time >= dateCriteria) select lastt.time).ToArray(); foreach (DateTime d in dis_lastweek) { if (d.Date == allDates[0]) { model.dis_day1 += 1; } else if (d.Date == allDates[1]) { model.dis_day2 += 1; } else if (d.Date == allDates[2]) { model.dis_day3 += 1; } else if (d.Date == allDates[3]) { model.dis_day4 += 1; } else if (d.Date == allDates[4]) { model.dis_day5 += 1; } else if (d.Date == allDates[5]) { model.dis_day6 += 1; } else if (d.Date == allDates[6]) { model.dis_day7 += 1; } else if (d.Date == allDates[7]) { model.dis_day8 += 1; } } }