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?
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.
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.
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.
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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With