问题描述
我将DotNet.Highcharts与Visual Studio 2010结合使用。我创建了一个Series数组:
List<系列> allSeries =新列表< Series>();
然后通过数据库循环并添加了几个不同的系列。然后我创建了一个Highchart,并且需要将allSeries列表添加到它。我有下面的代码,我一次创建一个系列。
.SetSeries(new []
{$ b我怎样才能把allSeries列表传递给SetSeries? $ b new Series {Name =Combiner 2,Data = new Data(myData2)},
new Series {Name =Combiner 3,Data = new Data(myData3)}
});
如果我假设 myData2
和 myData3
对象包含在或可以从 allSeries
中提取,那么你应该可以这样做:
.SetSeries(allSeries.Select(s => new Series {Name = s.Name,Data = s.Data}));
编辑:
如果设置系列不寻找 IEnumerable< Series>
,而是需要 Object []
或 Series []
,那么你可以这样做:
pre code $>将系列元素转换为对象,然后投影到数组$ b $ SetSet(allSeries.Select (s =>(object)new Series {Name = s.Name,Data = s.Data})。ToArray());
或者这个:
//将系列元素投影到系列数组
.SetSeries(allSeries.Select(s => new Series {Name = s.Name,Data = s.Data})。ToArray ));
这一切都取决于 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) }
});
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.
这篇关于将系列列表传递给SetSeries的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!