【发布时间】:2018-05-18 18:10:16
【问题描述】:
我正在尝试在 y 轴 Canvas JS 图形上绘制三组不同的数据点(GraphPoints、GraphPoints1、GraphPoints2),但是当我在控制器代码上添加所有这些数据集时,不会绘制结果。如果我只添加一组(例如 y=s.GraphPoints1),则会生成图形并绘制结果。但是,我想要一个图表上 y 轴上的所有数据点集(GraphPoints、GraphPoints1、GraphPoints2)。我在将数据点集(GraphPoints、GraphPoints1、GraphPoints2)放在 y 下时遇到问题。请有人帮助,让我知道我做错了什么。谢谢!
这行得通:
public ActionResult Graph(int machineId)
{
using (var db = new DatabaseModel())
{
var sheets = db.Checksheets
.Where(s => s.MachineId == machineId)
.ToList()
.Select(s => new
{
label = $"O: {s.OrderNum} P: {s.PartNum}",
y = s.GraphPoints
});
return Json(sheets, JsonRequestBehavior.AllowGet);
}
}
这不起作用,但我想要这样的东西,所有数据点集都在一个图表上:
public ActionResult Graph(int machineId)
{
using (var db = new DatabaseModel())
{
var sheets = db.Checksheets
.Where(s => s.MachineId == machineId)
.ToList()
.Select(s => new
{
label = $"O: {s.OrderNum} P: {s.PartNum}",
y = $"{s.GraphPoints} {s.GraphPoints1} {s.GraphPoints2}"
});
return Json(sheets, JsonRequestBehavior.AllowGet);
}
}
这是记录图形点的 SQL 表:
GraphPoints GraphPoints1 GraphPoints2
50 45 60
30 12 100
56 89 67
【问题讨论】:
-
什么是“不起作用”?你能更具体一点吗?你有错误吗?出乎意料的结果?你期待什么?
-
我正在尝试在 y 轴 Canvas JS 图上绘制三组不同的数据点(GraphPoints、GraphPoints1、GraphPoints2),但是当我在控制器代码中添加所有这些数据集时,结果不会被绘制。如果我只添加一组(例如 y=s.GraphPoints1),则会生成图形并绘制结果。但是,我想要一个图表上 y 轴上的所有数据点集(GraphPoints、GraphPoints1、GraphPoints2)。这有意义吗?
-
另外,你的表结构是什么样的?样本行数据?
-
@Matt 我正在尝试创建一个 Canvas JS 图。有关详细信息,请参阅我上面的更新代码。
-
你可以试试这样的:
.SelectMany(s => new[] { new{ label = $"O: {s.OrderNum} P: {s.PartNum}", y = s.GraphPoints}, new{ label = $"O: {s.OrderNum} P: {s.PartNum}", y = s.GraphPoints1}, new{ label = $"O: {s.OrderNum} P: {s.PartNum}", y = s.GraphPoints2} });