// GET: InvestAccounts public ActionResult Index() { GIUser u = (GIUser)Session["UserProfile"]; if (u == null) { return RedirectToAction("Index", "Home"); } var user = db.GIUsers.Where(a => a.Id == u.Id).First(); var context = new InvestContext(); foreach(var acount in user.BankAcounts) { context.addAcount(acount); } return View(context); }
public ActionResult Summary() { GIUser u = (GIUser)Session["UserProfile"]; if (u == null) { return PartialView("SessionTimeout"); } var user = db.GIUsers.Where(a => a.Id == u.Id).First(); var context = new InvestContext(); foreach (var account in user.BankAcounts) { context.addAcount(account); } return PartialView(context); }
public ActionResult StockTimeChart() { GIUser u = (GIUser)Session["UserProfile"]; var user = db.GIUsers.Where(a => a.Id == u.Id).First(); //DateTime mydate = new DateTime(2015, 9, 25); var context = new InvestContext(); foreach (var account in user.BankAcounts) { context.addAcount(account); } System.Web.UI.DataVisualization.Charting.Chart chart = new Chart(); chart.Height = 360; chart.Width = 420; chart.ChartAreas.Add(new ChartArea()); //chart.Legends.Add(new Legend("Legend")); //chart.Legends["Legend"].DockedToChartArea = "Default"; var now = DateTime.Now; string[] xline = { now.AddDays(-6).GetDateTimeFormats('m')[0].ToString(), now.AddDays(-5).GetDateTimeFormats('m')[0].ToString(), now.AddDays(-4).GetDateTimeFormats('m')[0].ToString(), now.AddDays(-3).GetDateTimeFormats('m')[0].ToString(), now.AddDays(-2).GetDateTimeFormats('m')[0].ToString(), now.AddDays(-1).GetDateTimeFormats('m')[0].ToString(), "今天" }; foreach(var account in user.BankAcounts) { if(account.StockAcounts.Count != 0) { foreach (var stock in account.StockAcounts) { double[] yline = { StockAPI.getValueAtDate(stock.Symbol, now.AddDays(-6)) * stock.Number, StockAPI.getValueAtDate(stock.Symbol, now.AddDays(-5)) * stock.Number, StockAPI.getValueAtDate(stock.Symbol, now.AddDays(-4)) * stock.Number, StockAPI.getValueAtDate(stock.Symbol, now.AddDays(-3)) * stock.Number, StockAPI.getValueAtDate(stock.Symbol, now.AddDays(-2)) * stock.Number, StockAPI.getValueAtDate(stock.Symbol, now.AddDays(-1)) * stock.Number, StockAPI.getStockValue(stock.Symbol).Item1 * stock.Number }; for (var i = 0; i < 7; i++) { if (stock.StartDate < now.AddDays(-6 + i)) { if (stock.EndDate != null && stock.EndDate < now.AddDays(-6 + i)) { yline[i] = 0; } } else { yline[i] = 0; } } chart.Series.Add(new Series(stock.Symbol)); chart.Series[stock.Symbol].ChartType = SeriesChartType.StackedColumn; chart.Series[stock.Symbol]["BorderColor"] = "Black"; chart.Series[stock.Symbol].Points.DataBindXY(xline, yline); // //chart.Series[stock.Symbol].Legend = "Legend"; //chart.Series[stock.Symbol].IsVisibleInLegend = true; //chart.Series[stock.Symbol].LegendText = stock.Symbol; } } } MemoryStream ms = new MemoryStream(); chart.SaveImage(ms, ChartImageFormat.Png); return File(ms.ToArray(), "image/png"); }
public ActionResult StockPieChart() { GIUser u = (GIUser)Session["UserProfile"]; var user = db.GIUsers.Where(a => a.Id == u.Id).First(); //DateTime mydate = new DateTime(2015, 9, 25); var context = new InvestContext(); foreach (var account in user.BankAcounts) { context.addAcount(account); } string[] pieNames = new string[context.stocks.Count]; double[] pieValues = new double[context.stocks.Count]; if (context.stocks.Count == 0) { //need to be implemented } else { for(var i = 0; i < context.stocks.Count; i++) { pieNames[i] = context.stocks[i].symbol; pieValues[i] = context.stocks[i].value; } } System.Web.UI.DataVisualization.Charting.Chart chart = new Chart(); chart.Height = 400; chart.Width = 400; chart.ChartAreas.Add(new ChartArea()); chart.Series.Add(new Series("Data")); chart.Series["Data"].ChartType = SeriesChartType.Pie; chart.Series["Data"]["PieLabelStyle"] = "Outside"; chart.Series["Data"]["PieLineColor"] = "Black"; chart.Series["Data"].Points.DataBindXY( pieNames, pieValues); //Other chart formatting and data source omitted. MemoryStream ms = new MemoryStream(); chart.SaveImage(ms, ChartImageFormat.Png); return File(ms.ToArray(), "image/png"); }
public ActionResult PieChart() { GIUser u = (GIUser)Session["UserProfile"]; var user = db.GIUsers.Where(a => a.Id == u.Id).First(); //DateTime mydate = new DateTime(2015, 9, 25); var context = new InvestContext(); foreach (var account in user.BankAcounts) { context.addAcount(account); } string[] pieNames = { "现金", "退休", "投资"}; double[] pieValues = { context.cashSum, context.retireSum, context.stockSum}; System.Web.UI.DataVisualization.Charting.Chart chart = new Chart(); chart.Height = 400; chart.Width = 400; chart.ChartAreas.Add(new ChartArea()); chart.Series.Add(new Series("Data")); chart.Series["Data"].ChartType = SeriesChartType.Pie; chart.Series["Data"]["PieLabelStyle"] = "Outside"; chart.Series["Data"]["PieLineColor"] = "Black"; chart.Series["Data"].Points.DataBindXY( pieNames, pieValues); //chart.Series["Data"].Label = "#PERCENT{P1}"; //Other chart formatting and data source omitted. MemoryStream ms = new MemoryStream(); chart.SaveImage(ms, ChartImageFormat.Png); return File(ms.ToArray(), "image/png"); }