How to Delete a Series or a Data Point of a Series from a PowerPoint Chart in Python?

I want to know how to delete a specific series or delete a specific datapoint of a series from ms chart using aspose.slides python via .net?

Thank you for contacting support.

I am working on the question and will get back to you as soon as possible.

The ChartSeriesCollection and ChartDataPointCollection classes contain methods to remove a series and data point respectively.

For example, let’s assume the first shape is a chart:

with slides.Presentation("test.pptx") as presentation:
    chart = presentation.slides[0].shapes[0]

Then you can remove a series from a chart like this:


or remove a data point like this:


Thanks for the reply. Although, it can delete the series but its not deleting the data when you go to chart data in PowerPoint and it also removes the mapping identifier( I am referring to the color schemes used to identify series and category) from chart data.

before.png (15.3 KB)
after.png (13.8 KB)
chart.chart_data.series.remove_at(1) -> I have used this code to remove the second series and have attached the actual chart data(before.png) before running the code and the resulted chart data(after.png) after running the code.

chart.chart_data.series[0].data_points.remove_at(0) -> also I used this code to remove the first data point from the first series but it didn’t work

Please suggest what’s the solution where I can actually delete the data from chart data as well as retain the mapping identifier.

Thank you for the information. Could you please share the presentation file with the chart you used?

Aspose (45.3 KB)
attached the powerpoint file.

Thank you for the sample files. I’ve reproduced the problems you described.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): 
    SLIDESNET-44211 (Failed to remove series data from a chart)
    SLIDESNET-44212 (Failed to remove a data point from a chart)

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Regarding deleting a series from the chart, please note that if you delete a series in the PowerPoint interface, the data will also remain.

Please try using the following code example to remove series data:

using Presentation presentation = new Presentation("Aspose test.pptx");

IChart chart = (IChart)presentation.Slides[0].Shapes[1];

foreach (IChartDataCell nameCell in chart.ChartData.Series[0].Name.AsCells)
    nameCell.Value = null;

foreach (IChartDataPoint point in chart.ChartData.Series[0].DataPoints)
    point.Value.AsCell.Value = null;


presentation.Save("output.pptx", SaveFormat.Pptx);

To delete a chart data point, please try using the following code snippet:

// Delete the first data point from the first sreries.
chart.ChartData.Series[0].DataPoints[0].Value.AsCell.Value = null;

The snippets you have shared are not in python. Please share a python based solution.

However, I tried to convert the second snippet into python that you shared. It’s not working actually. The problem that I mentioned in the original message(it deletes value from chart data but visually you won’t see any changes in the actual chart, I shared some attachments to support this as well) is still there.

I apologize for my mistake. I will get back to you as soon as possible.

Please try using the following code snippets.

To delete a chart data series:

with slides.Presentation("Aspose test.pptx") as presentation:
    chart = presentation.slides[0].shapes[1]

    for name_cell in chart.chart_data.series[0].name.as_cells:
        name_cell.value = None

    for point in chart.chart_data.series[0].data_points:
        point.value.as_cell.value = None

    chart.chart_data.series.remove_at(0)"output.pptx", slides.export.SaveFormat.PPTX)

Result: sample1.png (104.1 KB), (41.9 KB)

To delete a chart data point:

with slides.Presentation("Aspose test.pptx") as presentation:
    chart = presentation.slides[0].shapes[1]

    chart.chart_data.series[0].data_points[0].value.as_cell.value = None
    chart.chart_data.series[0].data_points.remove_at(0)"output.pptx", slides.export.SaveFormat.PPTX)

Result: sample2.png (103.6 KB), (43.0 KB)

I used Aspose.Slides for Python 23.9.

Thanks so much for the solution Andrey :slightly_smiling_face:. It’s working without any error.

Thank you for using Aspose.Slides.

The issues you have found earlier (filed as SLIDESNET-44212,SLIDESNET-44211) have been fixed in this update. This message was posted using Bugs notification tool by asad.ali


Sorry, the fixes for your issues are included in Aspose.Slides for .NET v23.11. Please try it.