How to remove chart axis and lines using C# with interop library?

406 views Asked by At

I have a chart with some data present in it. I don't want to show the x and Y axis. I somehow find out how to remove the legend in the chart. But failed to hide the axis.

enter image description here

I just want to remove the Grid line and Axes also. I have the chart object with the below code.

  PowerPoint.Shape chartShape = slide.Shapes.AddChart(Microsoft.Office.Core.XlChartType.xlBarClustered, left, top, width, height);

  //Get the chart
  PowerPoint.Chart chart = chartShape.Chart;
  chart.Legend.Clear();

Can anyone knows how to hide it with c#?

1

There are 1 answers

0
Andrey Potapov On

If you use Aspose.Slides for .NET instead of Office Interop, you will hide the chart legend, axes and gridlines as shown below:

    using var presentation = new Presentation();
    var chart = presentation.Slides[0].Shapes.AddChart(ChartType.ClusteredBar, 20, 20, 400, 300);
    
    chart.HasLegend = false;
    
    chart.Axes.VerticalAxis.IsVisible = false;
    chart.Axes.HorizontalAxis.IsVisible = false;
    
    chart.Axes.HorizontalAxis.MajorGridLinesFormat.Line.FillFormat.FillType = FillType.NoFill;
    
    // Save the chart with default data
    presentation.Save("result.pptx", SaveFormat.Pptx);

Result with default data:

enter image description here

Documentation | API Reference | Free forum

You can also evaluate Aspose.Slides Cloud for presentation manipulating. This REST-based API allows you to make 150 free API calls per month for API learning and presentation processing.

I work at Aspose.