Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a Map Chart in VSTO PowerPoint

I'm trying to add a map chart in PowerPoint.

As of now I can't see the option to do so in XlChartType, but if I insert one manually I can then examine the inserted chart and see that its XlChartType evaluates to 140.

If I try to insert a chart with this type I get a map chart as expected. However, if I try to access its workbook it throws an exception. These two lines of code should explain what I'm doing:

var chart = _slide.Shapes.AddChart((XlChartType)140).Chart;
var workbook = (Workbook)chart.ChartData.Workbook;

I assume this is related to the fact that it's not officially supported. Is there any way to work around this problem and edit the data of the chart?

like image 853
Frederik Hansen Avatar asked Aug 22 '18 09:08

Frederik Hansen


People also ask

Does PowerPoint consider a map to be a chart?

It’s not obvious – PowerPoint considers maps to be charts: On the PowerPoint Ribbon click on the Insert tab. Click “Chart” to open the Insert Chart dialog. Click on “Map” in the All Charts list.

How do you make a map in PowerPoint?

It’s not obvious – PowerPoint considers maps to be charts: 1 On the PowerPoint Ribbon click on the Insert tab. 2 Click “Chart” to open the Insert Chart dialog. 3 Click on “Map” in the All Charts list. 4 Click OK to insert a general world map into your PowerPoint presentation.

How do I format a map chart's series options?

Following are some guidelines for formatting a Map chart's Series Options. To display the Series Options for your map chart you can right-click on the outer portion of the map and select Format Chart Area in the right-click menu, or double-click on the outer portion of the map.

Is there a map chart in Excel 2016?

Note: Map charts are only available in Excel 2016 if you have a Microsoft 365 subscription. If you are a Microsoft 365 subscriber, make sure you have the latest version of Office. Note: There are several Map chart specific Series options, however they are not supported in Android devices or Excel Mobile.


1 Answers

I think you are missing call to Activate method.

Checkout remark from official source:

Note You must call the Activate method before referencing this property; otherwise, an error occurs.

Your code should be:

var chart = _slide.Shapes.AddChart((XlChartType)140).Chart;
chart.ChartData.Activate(); // missing piece
var workbook = (Workbook)chart.ChartData.Workbook;
like image 63
Dipen Shah Avatar answered Oct 18 '22 06:10

Dipen Shah