Daniel Hilgarth
Daniel Hilgarth

Reputation: 174467

Get category names of waterfall chart

I am trying to read the category names of a waterfall chart in a PowerPoint VSTO project.
So far, I was unable to do so.

Here is what I tried:

Then, I tried reading the source data directly via chart.ChartData.Workbook but this is also not available.

So, how can I read the category names?

Upvotes: 4

Views: 482

Answers (1)

joeschwa
joeschwa

Reputation: 3175

It appears that, as of this writing, the XlChartType enumeration is missing a member for Waterfall. (Waterfall has a ChartType integer value of 119, which is simply missing in the enumeration.)

As the missing enumeration creates all sorts of issues, I decided to write code that would convert the chart to an enumerated type, place the Category Names into an array, and then use PowerPoint's Undo functionality to restore the chart.

PowerPoint.Chart myChart = Globals.ThisAddIn.Application.ActivePresentation.Slides[1].Shapes[2].Chart;
myChart.ChartType = Office.XlChartType.xlBarStacked;
PowerPoint.Axis CategoryAxis = Globals.ThisAddIn.Application.ActivePresentation.Slides[1].Shapes[2].Chart.Axes(PowerPoint.XlAxisType.xlCategory, PowerPoint.XlAxisGroup.xlPrimary);
Array CatNames = (Array)((object)CategoryAxis.CategoryNames);
Globals.ThisAddIn.Application.CommandBars.ExecuteMso("Undo");
//Do something here with the CatNames array

Upvotes: 2

Related Questions