所以我设法根据当前的用户数据创建了一个图表,我正在尝试整理视图。到目前为止,视图占据整个页面并隐藏我的导航栏等。我试图将它包装在div,body中,但无法使其工作。我不是很擅长html / View部分(这很明显!)并且感觉好像我错过了一些简单的东西。
这是我的控制人:(我已删除了具体细节)
public async Task<ActionResult> DrawChart()
{
var currentUser = await manager.FindByIdAsync(User.Identity.GetUserId());
var data = new List<Data>(db.Data.ToList().Where(d => d.User.Id == currentUser.Id));
string connectionString = @"Data Source";
using (SqlConnection con = new SqlConnection(connectionString))
{
con.Open();
using (SqlCommand command = new SqlCommand("SELECT Required Data FROM Data WHERE User_Id = 'currentUserId'", con))
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
data.Add(new Data { Xdata = reader.GetDateTime(0), ydata = reader.GetDouble(1) });
}
}
}
return View(workouts);
}
这是我的观点:(再次删除了具体细节)
@model IEnumerable<MyModel>
@{
ViewBag.Title = "DrawChart";
}
@{
var myChart = new Chart(width: 800, height: 500)
.AddTitle("Insert Title")
.AddSeries(chartType: "Line",
xValue: Model, xField: "XData",
yValues: Model, yFields: "YData")
.Write("png")
.Save("png");
}
我从docs.microsoft尝试了这个建议:(哪些不起作用)
<!DOCTYPE html>
<html>
<head>
<title>Chart Example</title>
</head>
<body>
<h1>Chart Example</h1>
<p>The following chart is generated by the <em>ChartArrayBasic.cshtml</em> file, but is shown
in this page.</p>
<p><img src="ChartArrayBasic.cshtml" /> </p>
</body>
</html>
如何修复此视图?