我正在使用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 });
如图所示,我的数据包含两个值:
和
当我将代码更改为此时,它有用吗?
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 });
结果:
答案 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 });
正如你所看到的,我创建了一个对象数组并将我的列表转换为该对象并将对象数组传递给我的图表。