Linger
Linger

Reputation: 15058

Pass a List of Series to SetSeries

I am using DotNet.Highcharts in conjunction with Visual Studio 2010. I have created an array of Series:

List<Series> allSeries = new List<Series>();

I then looped through a database and added several different Series. Then I created a Highchart and need to add the allSeries list to it. I have the code below that I used to create a Series one at a time. How can I take the allSeries list and pass it to SetSeries?

.SetSeries(new[]
           {
               new Series { Name = "Combiner 2", Data = new Data(myData2) },
               new Series { Name = "Combiner 3", Data = new Data(myData3) }
           });

Upvotes: 4

Views: 1476

Answers (1)

Jonathan Bates
Jonathan Bates

Reputation: 1835

if I am left to assume that the myData2 and myData3 objects are contained in or could be extracted from allSeries, then you should be able to do something like this:

.SetSeries(allSeries.Select(s=> new Series { Name = s.Name, Data = s.Data }));

EDIT: If set series isn't looking for an IEnumerable<Series> but instead needs Object[] or Series[], then you could do this:

//casts series elements to object, then projects to array
.SetSeries(allSeries.Select(s=> (object)new Series { Name = s.Name, Data = s.Data }).ToArray());

or maybe this:

//projects series elements to array of series
.SetSeries(allSeries.Select(s=> new Series { Name = s.Name, Data = s.Data }).ToArray());

it all depends on what the method signature for SetSeries is.

Upvotes: 4

Related Questions