0

I'm creating a chart (of ComboChart type) in the PPTX file using GemBox.Presentation (together with GemBox.Spreadsheet). I'm using the code from the PowerPoint Chart example and added parts of the Excel Combo Chart example.

This is what I have so far:

var presentation = new PresentationDocument();
var slide = presentation.Slides.AddNew(SlideLayoutType.Custom);
var chart = slide.Content.AddChart(GemBox.Presentation.ChartType.Combo, 25, 25, 300, 500);
var comboChart = (ComboChart)chart.ExcelChart;
var worksheet = comboChart.Worksheet;

worksheet.Cells["A1"].Value = "Name";
worksheet.Cells["A2"].Value = "John Doe";
worksheet.Cells["A3"].Value = "Fred Nurk";

worksheet.Cells["B1"].Value = "Salary";
worksheet.Cells["B2"].Value = 4023;
worksheet.Cells["B3"].Value = 3263;

worksheet.Cells["C1"].Value = "Max";
worksheet.Cells["C2"].Value = 4500;
worksheet.Cells["C3"].Value = 4300;

worksheet.Cells["D1"].Value = "Min";
worksheet.Cells["D2"].Value = 3000;
worksheet.Cells["D3"].Value = 2800;

comboChart.CategoryLabelsReference = "A2:A3";

var salaryChart = comboChart.Add(GemBox.Spreadsheet.Charts.ChartType.Column);
salaryChart.Series.Add("=B1", "B2:B3");

var minMaxChart = comboChart.Add(GemBox.Spreadsheet.Charts.ChartType.Line);
minMaxChart.Series.Add("=C1", "C2:C3");
minMaxChart.Series.Add("=D1", "D2:D3");

presentation.Save("output.pptx");

And this is what I get: Combo chart in PPTX file

Now my problem is that I cannot find any way to access and format the Category axis and Vertical axis.

I tried to use chart, comboChart, salaryChart, and minMaxChart objects, but none of them have any axes properties!?

How can I, let's say, set the axes titles?

1 Answers1

1

To set the axes of the Combo chart, you'll need to use the axes of one of its containing charts, so either salaryChart or minMaxChart.

Now the reason why you don't see any axes properties on them is that they are of a base type (ExcelChart). You need to cast them to a derived type, like this:

var salaryChart = (ColumnChart)comboChart.Add(GemBox.Spreadsheet.Charts.ChartType.Column);
salaryChart.Series.Add("=B1", "B2:B3");

salaryChart.Axes.Horizontal.Title.Text = "My Categories";
salaryChart.Axes.Vertical.Title.Text = "My Values";
Mario Z
  • 4,328
  • 2
  • 24
  • 38
  • I tried to access axes property from excelChart base type however I get error as my scenario is same to the question trying to make chart using spreadsheet on powerpoint. Error say : `ExcelChart does not contain definition for axes and no accessible extension method axes accepting a first argument of type ExcelChart could be found`. could you please help. Thanks. – Bheeshma Nov 12 '21 at 01:10
  • @user273181 the base type doesn't have axes because not all charts have axes. You'll need to cast your chart into one of the derived types, like `ColumnChart` that is used in the above answer. – Mario Z Nov 12 '21 at 03:19
  • okay i understand what u mean. Thanks for quick reply. – Bheeshma Nov 12 '21 at 03:27