private void AddPieChart() { var anchorRow = 5 + _budget.Categories.Count; var chartSpec = new ChartSpec() { Title = "Categories share", PieChart = new PieChartSpec() { LegendPosition = "LABELED_LEGEND", PieHole = 0.65, Series = new ChartData() { SourceRange = new ChartSourceRange() { Sources = new List <GridRange>() { new GridRange() { StartColumnIndex = 1, EndColumnIndex = 2, StartRowIndex = 1, EndRowIndex = 2 + _budget.Categories.Count, SheetId = 2, } } } }, Domain = new ChartData() { SourceRange = new ChartSourceRange() { Sources = new List <GridRange>() { new GridRange() { StartColumnIndex = 0, EndColumnIndex = 1, StartRowIndex = 1, EndRowIndex = 2 + _budget.Categories.Count, SheetId = 2, } } } } } }; _googleSheetService.AddChart(0, anchorRow, chartSpec); }
public void AddChart(int anchorCol, int anchorRow, ChartSpec chartSpec) { var embededChart = new EmbeddedChart(); embededChart.Position = new EmbeddedObjectPosition() { OverlayPosition = new OverlayPosition() { AnchorCell = new GridCoordinate() { SheetId = _sheet.Properties.SheetId, ColumnIndex = anchorCol, RowIndex = anchorRow, } } }; embededChart.Spec = chartSpec; _sheet.Charts.Add(embededChart); }
private void AddBarChart() { var anchorRow = 5 + _budget.Categories.Count + 2 * 18; var chartSpec = new ChartSpec() { Title = "Spending in categories", BasicChart = new BasicChartSpec() { ChartType = "COLUMN", Series = new List <BasicChartSeries>() { new BasicChartSeries() { Series = new ChartData() { SourceRange = new ChartSourceRange() { Sources = new List <GridRange>() { new GridRange() { StartColumnIndex = 1, EndColumnIndex = 2, StartRowIndex = 2, EndRowIndex = 2 + _budget.Categories.Count, SheetId = 2, } } }, }, Color = new Color() { Alpha = 1, Red = (float)0x8e / 256, Green = (float)0x7c / 256, Blue = (float)0xc3 / 256, }, }, }, Domains = new List <BasicChartDomain>() { new BasicChartDomain() { Domain = new ChartData() { SourceRange = new ChartSourceRange() { Sources = new List <GridRange>() { new GridRange() { StartColumnIndex = 0, EndColumnIndex = 1, StartRowIndex = 2, EndRowIndex = 2 + _budget.Categories.Count, SheetId = 2, } } }, }, } } } }; _googleSheetService.AddChart(0, anchorRow, chartSpec); }
private void SmootheLineChart() { var anchorRow = 5 + _budget.Categories.Count + 18; int lastCategoryRowIndex = _budget.Categories.Last().RowIndex; _log.LogInformation($"Last Category index: {lastCategoryRowIndex}"); var chartSpec = new ChartSpec() { Title = "Cumulative spending", BasicChart = new BasicChartSpec() { ChartType = "LINE", LegendPosition = "NO_LEGEND", LineSmoothing = true, Axis = new List <BasicChartAxis>() { new BasicChartAxis() { Position = "BOTTOM_AXIS", Title = "Day", TitleTextPosition = new TextPosition() { HorizontalAlignment = "CENTER" } }, new BasicChartAxis() { Position = "LEFT_AXIS", Title = "Total spent", TitleTextPosition = new TextPosition() { HorizontalAlignment = "CENTER" }, }, }, Series = new List <BasicChartSeries>() { new BasicChartSeries() { Series = new ChartData() { SourceRange = new ChartSourceRange() { Sources = new List <GridRange>() { new GridRange() { StartColumnIndex = 6, EndColumnIndex = 6 + DateTime.DaysInMonth(_budget.Month.Year, _budget.Month.Month), StartRowIndex = lastCategoryRowIndex + 2 + _budget.Subcategories.Where(x => x.CategoryId == _budget.Categories.Last().Id).Count() + 2, EndRowIndex = lastCategoryRowIndex + 2 + _budget.Subcategories.Where(x => x.CategoryId == _budget.Categories.Last().Id).Count() + 1 + 2, SheetId = 1, }, } }, }, Color = new Color() { Alpha = 1, Red = (float)0x93 / 256, Green = (float)0xc4 / 256, Blue = (float)0x7d / 256, }, }, }, Domains = new List <BasicChartDomain>() { new BasicChartDomain() { Domain = new ChartData() { SourceRange = new ChartSourceRange() { Sources = new List <GridRange>() { new GridRange() { StartColumnIndex = 6, EndColumnIndex = 6 + DateTime.DaysInMonth(_budget.Month.Year, _budget.Month.Month), StartRowIndex = lastCategoryRowIndex + 2, EndRowIndex = lastCategoryRowIndex + 3, SheetId = 1, }, } }, }, } } } }; _log.LogInformation($"Line chart spec: {Newtonsoft.Json.JsonConvert.SerializeObject(chartSpec)}"); _googleSheetService.AddChart(0, anchorRow, chartSpec); }