2
public static Series MeterReadingsToPieChart(IEnumerable<Dictionary<string, double>> readings)
{
    object[] points = ? // I dont know how can I create this array from readings.

    Series series = new Series
    {
        Type = ChartTypes.Pie,
        Name = "",
        Data = new Data(points)
    };

    return series;
}

我想从上面的代码动态创建以下

Series series = new Series
{
    Type = ChartTypes.Pie,
    Name = "",
    Data = new Data(new object[]
           {
               new object[] { "Gaziemir", 45.0 },
               new object[] { "Bornova", 26.8 },
               new object[] { "Forum Bornova", 8.5 }
           })
};

你能给出一个起点吗?

谢谢

4

1 回答 1

3

为了匹配底部的代码,那就是:

object[][] points = readings.Select(
      pair => new object[] { pair.Key, pair.Value }).ToArray();

Series series = new Series
{
    Type = ChartTypes.Pie,
    Name = "",
    Data = new Data(points))
};

但是,就我个人而言,我会说这object[][]不是最好的选择......

于 2013-02-26T07:25:05.213 回答