我对 C# 和 MVC 非常陌生,我正在创建一个 Web 应用程序。我正在尝试使用 DotNet High Chart 创建一个折线图,它将使用我的数据库中的数据进行填充。我在将 DateTime 转换为字符串时遇到问题。我的图表控制器是:
var dataLeft = (from d in db.Appointments
select new
{
Date = d.Date.ToString("yyyyMMdd"),
IOPLeft = d.IOPLeft,
}).ToList();
var xSeries = dataLeft.Select(a => a.Date).ToArray();
var ySeries = dataLeft.Select(a => a.IOPLeft).ToArray();
// instantiate an object of the high charts type
var chart = new Highcharts("chart")
// define the type of chart
.InitChart(new Chart { DefaultSeriesType = ChartTypes.Line })
//overall title of the chart
.SetTitle(new Title { Text = "Left IOP" })
//small label below the main title
.SetSubtitle(new Subtitle { Text = "LeftIOP" })
// load the x values
.SetXAxis(new XAxis { Categories = xSeries })
// set the y title
.SetYAxis(new YAxis { Title = new YAxisTitle { Text = "IOP" } })
.SetTooltip(new Tooltip
{
Enabled = true,
Formatter = @"function() { return '<b>'+this.series.name +'</b><br/>'+this.x+': '+this.y;}"
})
.SetPlotOptions(new PlotOptions
{
Line = new PlotOptionsLine
{
DataLabels = new PlotOptionsLineDataLabels
{
Enabled = true
},
EnableMouseTracking = false
}
})
//load y values
.SetSeries(new[]
{
new Series {Name = "Patient",
Data = new Data(new object[] {ySeries})},
});
return View(chart);
}
}
}
我的模型:
[Display(Name = "Date")]
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime Date { get; set; }
[Display(Name = "Left IOP")]
public int IOPLeft { get; set; }
当我尝试运行应用程序时,出现以下错误:
EntityFramework.SqlServer.dll 中出现“System.NotSupportedException”类型的异常,但未在用户代码中处理
附加信息:LINQ to Entities 无法识别方法“System.String ToString(System.String)”方法,并且此方法无法转换为存储表达式。
任何 hep 将不胜感激谢谢