When creating chart, the legend appears by default. If we just need the chart series rather than the legend, we can delete the legend entries after creating the chart. Spire.Presentation supports to delete legend entries from chart by using ChartLegend.DeleteEntry method. This article is going to demonstrate how we can use Spire.Presentation to accomplish this function.
Below screenshot shows the example PowerPoint file which contains 3 chart legend entries:
Detail steps:
Step 1: Initialize an object of Presentation class and load the PowerPoint file.
Presentation ppt = new Presentation(); ppt.LoadFromFile("Input.pptx");
Step 2: Get the chart.
IChart chart = ppt.Slides[0].Shapes[0] as IChart;
Step 3: Delete the first and the second legend entries from the chart.
chart.ChartLegend.DeleteEntry(0); chart.ChartLegend.DeleteEntry(1);
Step 4: Save the file.
ppt.SaveToFile("Output.pptx", FileFormat.Pptx2010);
Screenshot:
Full code:
using Spire.Presentation; using Spire.Presentation.Charts; namespace Delete_chart_legend_entries_in_PPT { class Program { static void Main(string[] args) { Presentation ppt = new Presentation(); ppt.LoadFromFile("Input.pptx"); IChart chart = ppt.Slides[0].Shapes[0] as IChart; chart.ChartLegend.DeleteEntry(0); chart.ChartLegend.DeleteEntry(1); ppt.SaveToFile("Output.pptx", FileFormat.Pptx2010); } } }