Bar highchart只显示我的数组的一个值

时间:2016-02-09 05:34:40

标签: c# asp.net asp.net-mvc highcharts

我正在使用highchart在mvc中绘制条形图。您可以在此处看到我的代码:

   Highcharts chartArticleCount = new Highcharts("chart1")
                  .SetXAxis(new XAxis { Categories = majors })
                  .SetYAxis(new YAxis { Title = new YAxisTitle { Text = "تعداد مقالات" } })
                  .SetSeries(new Series { Data = new Data(new object[] {majorArticleCount.ToArray()}), Name = "محور های همایش" })
                  .SetTitle(new Title { Text = "" })
                  .InitChart(new Chart { DefaultSeriesType = ChartTypes.Column });

如图所示,我的数据包含两个值:

enter image description here

enter image description here

但图表只显示其中一个最后一个值。为什么? enter image description here

当我将代码更改为此时,它有用吗?

 Highcharts chartArticleCount = new Highcharts("chart1")
                  .SetXAxis(new XAxis { Categories = new string[]{"salam","khobi"} })
                  .SetYAxis(new YAxis { Title = new YAxisTitle { Text = "تعداد مقالات" } })
                  .SetSeries(new Series { Data = new Data(new object[] {"1","2"}), Name = "محور های همایش" })
                  .SetTitle(new Title { Text = "" })
                  .InitChart(new Chart { DefaultSeriesType = ChartTypes.Column });

结果:

enter image description here

1 个答案:

答案 0 :(得分:0)

问题在于:

majorArticleCount.ToArray()

这是整数列表,应该转换为object:

object[] pointnum = new object[majorArticleCount.Count];
            pointnum = majorArticleCount.Cast<object>().ToArray();
            Highcharts chartArticleCount = new Highcharts("chart1")
                      .SetXAxis(new XAxis { Categories = majors })
                      .SetYAxis(new YAxis { Title = new YAxisTitle { Text = "تعداد مقالات" } })
                      .SetSeries(new Series { Data = new Data(pointnum.ToArray()), Name = "محور های همایش" })
                      .SetTitle(new Title { Text = "" })
                      .InitChart(new Chart { DefaultSeriesType = ChartTypes.Column });

正如你所看到的,我创建了一个对象数组并将我的列表转换为该对象并将对象数组传递给我的图表。