0
我無法使用數據庫中的數據構建圖表。試過這樣的,但它不工作無法使用數據庫中的數據構建圖表
控制器:
public ActionResult Chart()
{
return PartialView("_Chart");
}
在主視圖:
img src="@Url.Action("Chart")"/>
局部視圖(_Chart.cshtml):
@using TestProject.Models;
@{
DateTime[] xVal = new DateTime();
Decimal[] yVal = new Decimal();
TestProjectContext db = new TestProjectContext();
var deals = from d in db.DealsDirectory
select d;
deals.ToList().ForEach(x => xVal.Add(x.Date));
deals.ToList().ForEach(y => yVal.Add(y.Price));
var Chart = new Chart(width: 600, height: 400)
.AddTitle("Зависимость цены от времени")
.AddSeries(
name: "USD",
xValue: xVal,
yValues: yVal,
chartType:"Line")
.Write();
}