Search code examples
c#asp.net-mvcchartsdotnethighcharts

HighCharts .NET X-Axis definition


I have a list with values. I want to show a HighCharts .NET chart based on these values. The problem is: I have to set the chart properties in my code. It looks like this:

  Highcharts chart = new Highcharts("chart");

            chart.SetXAxis(new XAxis
            {
                Categories = new[] { results.date[0], results.date[1], results.date[2] }
            });

            chart.SetSeries(new Series
            {
                Data = new Data(new object[]
                    {results.Values[0], results.Values[1], results.Values[2]})
            });

So now, the chart only work if my list contains three values. But maybe the list has 20, 40, or more values. How can i code that?

Thanks for help


Solution

  • Found a solution:

                chart.SetXAxis(new[]
                {
                    new XAxis { Categories = results.Date.ToArray()}
                });
    
                chart.SetSeries(
                    new Series
                    {
                        Data = new Data(results.Values.Cast<object>().ToArray())
                    }
                );