我需要帮助。我正在尝试用数据库中的数据填充highcharts。
这非常有效:
public ActionResult Index()
{
Highcharts chart1 = new Highcharts("chart1")
.SetYAxis(new YAxis { Title = new YAxisTitle { Text = "Zmiana" } })
.SetTitle(new Title { Text = "Zmiany wartości portfela w czasie" })
.InitChart(new Chart { DefaultSeriesType = ChartTypes.Column })
.SetLegend(new Legend { Enabled = false })
.SetXAxis(new XAxis { Categories = new[] { "Styczeń", "Luty", "Marzec", "Kwiecień" } })
.SetSeries(new Series { Data = new Data(new object[] { 1, 8, 9, 6 }), Name = "Miesiąc" });
但这不是:
public ActionResult Index()
{
Highcharts chart1 = new Highcharts("chart1")
.SetYAxis(new YAxis { Title = new YAxisTitle { Text = "Zmiana" } })
.SetTitle(new Title { Text = "Zmiany wartości portfela w czasie" })
.InitChart(new Chart { DefaultSeriesType = ChartTypes.Column })
.SetLegend(new Legend { Enabled = false })
.SetXAxis(new XAxis { Type = AxisTypes.Datetime })
.SetSeries(new[]
{
new Series
{
Name = "Miesiąc" ,
Data = new Data(db.Wyniki.Select(x=> new Point {X=x.ID, Y=x.ID}).ToArray())
}
});
我有这个错误:
无法将类型'System.Int32'强制转换为'DotNet.Highcharts.Helpers.Number'类型。 LINQ to Entities仅支持转换EDM原语或枚举类型
我尝试了很多解决方案,但无法解决这个问题并用数据填充高级图表。
答案 0 :(得分:1)
替换
Data = new Data(db.Wyniki.Select(x=> new Point {X=x.ID, Y=x.ID}).ToArray())
通过
Data = new Data(db.Wyniki.ToList().Select(x=> new Point {Y=x.ID}).ToArray())
可能会完成这项工作;)