Pass a List of Series to SetSeries

…衆ロ難τιáo~ 提交于 2019-12-22 08:43:51

问题


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) }
           });

回答1:


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.



来源:https://stackoverflow.com/questions/10074620/pass-a-list-of-series-to-setseries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!