Ehsan Akbar February 2016

convert list<int> to object

i am trying to create a chart in mvc with highchart so as you can see this is my chart:

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

The problem is here :

Data = new Data(new object[] {312})

Instead 312 i want to pass a list<int> that contains 312 as you can see here:

List<int> majorArticleCount=new List<int>();
Data = new Data(new object[] {majorArticleCount})

This list majorArticleCount contains 312 but i get this error :

 Parameter count mismatch. 

How can i convert the list to object ?

Answers


Shyju February 2016

This should give you a list of int with 312 as the first(and only) item in it.

new List<int> {312};

So your code will be

Data = new Data(new object[] { new List<int> { 312 } })


jasonwarford February 2016

I'm not sure what Data is but you might try something like this:

List<int> majorArticleCount = new List<int>();

majorArticleCount.Add(312);

Data = new Data(new object[] { majorArticleCount.ToArray()});

Post Status

Asked in February 2016
Viewed 3,290 times
Voted 5
Answered 2 times

Search




Leave an answer