0

I need help. I'm trying to populate highcharts with data from a database.

This works perfectly:

    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" });

But this does not:

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())             
                            }
                        });

I have this error:

Unable to cast the type 'System.Int32' to type 'DotNet.Highcharts.Helpers.Number'. LINQ to Entities only supports casting EDM primitive or enumeration types

I tried many solutions, but couldn't solve that and populate highcharts with data.

1 Answer 1

1

replace

Data = new Data(db.Wyniki.Select(x=> new Point {X=x.ID, Y=x.ID}).ToArray())

by

Data = new Data(db.Wyniki.ToList().Select(x=> new Point {Y=x.ID}).ToArray())

might do the job ;)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.