public static bool IsValidColumn(string columnLabel, GoogleChartJson googleChartJson)
 {
     if (googleChartJson.ChartColumns == null || !googleChartJson.ChartColumns.Any())
     {
         return(true);
     }
     return(googleChartJson.ChartColumns.Contains(columnLabel));
 }
 public ViewGoogleChartViewData(GoogleChartJson googleChartJson, string chartTitle, int chartHeight, bool showChartTitle) : this(googleChartJson == null ? new List <GoogleChartJson>() : new List <GoogleChartJson> {
     googleChartJson
 },
                                                                                                                                 chartTitle,
                                                                                                                                 chartHeight,
                                                                                                                                 null,
                                                                                                                                 chartTitle.Replace(" ", ""),
                                                                                                                                 false,
                                                                                                                                 SitkaRoute <GoogleChartController> .BuildUrlFromExpression(c => c.DownloadChartData()),
                                                                                                                                 showChartTitle,
                                                                                                                                 true,
                                                                                                                                 null,
                                                                                                                                 false)
 {
 }
示例#3
0
        public static List <GoogleChartDataSimple> DeriveSimplesFromGoogleChartJson(GoogleChartJson googleChartJson)
        {
            var googleChartColumns = googleChartJson.GoogleChartDataTable.GoogleChartColumns;

            return(googleChartJson.GoogleChartDataTable.GoogleChartRowCs.Select(googleChartRowC =>
            {
                return new GoogleChartDataSimple
                {
                    ColumnValues = googleChartColumns.Where(x => x.ColumnLabel != null)
                                   .ToDictionary(x => x.ColumnLabel,
                                                 x =>
                    {
                        var index = googleChartColumns.IndexOf(x);
                        return index < googleChartRowC.GoogleChartRowVs.Count ? googleChartRowC.GoogleChartRowVs[index] : null;
                    })
                };
            })
                   .ToList());
        }
        public static List <PerformanceMeasureChartDataSimple> DeriveSimplesFromGoogleChartJson(GoogleChartJson googleChartJson, string mainColumnLabel)
        {
            var googleChartColumns   = googleChartJson.GoogleChartDataTable.GoogleChartColumns;
            var mainColumnLabelIndex = googleChartColumns.FindIndex(x => x.ColumnLabel == mainColumnLabel);

            var googleChartDataSimples = googleChartJson.GoogleChartDataTable.GoogleChartRowCs.Select(googleChartRowC =>
            {
                return(new PerformanceMeasureChartDataSimple
                {
                    Year = googleChartRowC.GoogleChartRowVs[mainColumnLabelIndex].Value.ToString(),
                    SubcategoryOptionValues = googleChartColumns.Where(x => x.ColumnLabel != null && IsValidColumn(x.ColumnLabel, googleChartJson))
                                              .ToDictionary(x => x.ColumnLabel, x => googleChartRowC.GoogleChartRowVs[googleChartColumns.IndexOf(x)])
                });
            })
                                         .ToList();

            googleChartDataSimples.Sort((x, y) => String.Compare(x.Year, y.Year, StringComparison.Ordinal));

            // Add total row
            googleChartDataSimples.Add(new PerformanceMeasureChartDataSimple
            {
                Year = "Total",
                SubcategoryOptionValues = googleChartDataSimples.SelectMany(x => x.SubcategoryOptionValues.Keys)
                                          .Distinct()
                                          .ToDictionary(x => x,
                                                        x =>
                {
                    var columnDataType = googleChartColumns.Single(y => y.ColumnLabel == x).ColumnDataType;
                    return(new GoogleChartRowV(googleChartDataSimples.Sum(y =>
                    {
                        var value = y.SubcategoryOptionValues[x].Value;
                        return columnDataType == GoogleChartColumnDataType.Number.ColumnDataType && value != null ? Decimal.Parse(value.ToString(), System.Globalization.NumberStyles.Float) : 0;
                    }),
                                               GoogleChartColumnDataType.Number.ColumnDataType));
                })
            });

            return(googleChartDataSimples);
        }