简体   繁体   English

HighCharts .NET X轴定义

[英]HighCharts .NET X-Axis definition

I have a list with values. 我有一个值列表。 I want to show a HighCharts .NET chart based on these values. 我想显示基于这些值的HighCharts .NET图表。 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. 但是列表可能包含20、40或更多的值。 How can i code that? 我该如何编码?

Thanks for help 感谢帮助

Found a solution: 找到一个解决方案:

            chart.SetXAxis(new[]
            {
                new XAxis { Categories = results.Date.ToArray()}
            });

            chart.SetSeries(
                new Series
                {
                    Data = new Data(results.Values.Cast<object>().ToArray())
                }
            );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM