//TODO: The GetFullCategoryYearDictionary and GetGoogleChartDataTable functions are probably fine in this Extension class, but the ToGoogleChart functions are more about display and probably could be in a better location public static GoogleChartJson ToGoogleChart(this IEnumerable <ProjectGrantAllocationExpenditure> projectGrantAllocationExpenditures, Func <ProjectGrantAllocationExpenditure, string> filterFunction, List <string> filterValues, Func <ProjectGrantAllocationExpenditure, IComparable> sortFunction, List <int> rangeOfYears, string chartContainerID, string chartTitle, GoogleChartType googleChartType, bool isStacked) { var fullCategoryYearDictionary = GetFullCategoryYearDictionary(projectGrantAllocationExpenditures, filterFunction, filterValues, sortFunction, rangeOfYears); var googleChartDataTable = GetGoogleChartDataTable(fullCategoryYearDictionary, rangeOfYears, googleChartType); var googleChartAxis = new GoogleChartAxis("Annual Expenditures", MeasurementUnitTypeEnum.Dollars, GoogleChartAxisLabelFormat.Short); var googleChartConfiguration = new GoogleChartConfiguration(chartTitle, isStacked, googleChartType, googleChartDataTable, new GoogleChartAxis(FieldDefinition.ReportingYear.GetFieldDefinitionLabel(), null, null), new List <GoogleChartAxis> { googleChartAxis }); var googleChart = new GoogleChartJson(chartTitle, chartContainerID, googleChartConfiguration, googleChartType, googleChartDataTable, null); return(googleChart); }
/// <summary> /// Enum types are equal by primary key /// </summary> public bool Equals(GoogleChartType other) { if (other == null) { return(false); } return(other.GoogleChartTypeID == GoogleChartTypeID); }
private static GoogleChartDataTable GetGoogleChartDataTable(Dictionary <string, Dictionary <int, decimal> > fullCategoryYearDictionary, List <int> rangeOfYears, GoogleChartType columnDisplayType) { var googleChartRowCs = new List <GoogleChartRowC>(); var sortedYearCategoryDictionary = fullCategoryYearDictionary.OrderBy(x => x.Value.Sum(y => y.Value)).ThenBy(x => x.Key).ToList(); foreach (var year in rangeOfYears.OrderBy(x => x)) { var googleChartRowVs = new List <GoogleChartRowV> { new GoogleChartRowV(year, year.ToString()) }; googleChartRowVs.AddRange( sortedYearCategoryDictionary .Select(x => x.Key) .Select(category => fullCategoryYearDictionary[category][year]) .Select(value => new GoogleChartRowV(value, GoogleChartJson.GetFormattedValue((double)value, MeasurementUnitType.Dollars)))); googleChartRowCs.Add(new GoogleChartRowC(googleChartRowVs)); } var columnLabel = FieldDefinition.ReportingYear.GetFieldDefinitionLabel(); var googleChartColumns = new List <GoogleChartColumn> { new GoogleChartColumn(columnLabel, columnLabel, "string") }; googleChartColumns.AddRange( sortedYearCategoryDictionary.Select( x => new GoogleChartColumn(x.Key, x.Key, "number", new GoogleChartSeries(columnDisplayType, GoogleChartAxisType.Primary), null, null))); return(new GoogleChartDataTable(googleChartColumns, googleChartRowCs)); }