Sometimes, the values in a chart vary widely from data series to data series, so it is difficult for us to compare the data only based on the primary vertical axis. To make the chart easier to read, you can plot one or more data series on a secondary axis. This article presents how to add secondary value axis to PowerPoint chart using Spire.Presentation in C# and VB.NET.
As is shown in the following combination chart, we can hardly learn the information of Series 3 since it contains different type of data compared with Series 1 and Series 2. In such cases, it is necessary to add a secondary axis to display the value of Series 3.
Test File:
Code Snippet:
Step 1: Create a new PowerPoint document and load the test file.
Presentation ppt = new Presentation("Test.pptx", FileFormat.Pptx2010);
Step 2: Get the chat from the PowerPoint file.
IChart chart = ppt.Slides[0].Shapes[0] as IChart;
Step 3: Add a secondary axis to display the value of Series 3.
chart.Series[2].UseSecondAxis = true;
Step 4: Set the grid line of secondary axis as invisible.
chart.SecondaryValueAxis.MajorGridTextLines.FillType=FillFormatType.None;
Step 5: Save the file.
ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010);
Result:
Entire Code:
using Spire.Presentation; using Spire.Presentation.Charts; using Spire.Presentation.Drawing; namespace AddValue { class Program { static void Main(string[] args) { Presentation ppt = new Presentation("Test.pptx", FileFormat.Pptx2010); IChart chart = ppt.Slides[0].Shapes[0] as IChart; chart.Series[2].UseSecondAxis = true; chart.SecondaryValueAxis.MajorGridTextLines.FillType = FillFormatType.None; ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010); } } }
Imports Spire.Presentation Imports Spire.Presentation.Charts Imports Spire.Presentation.Drawing Namespace AddValue Class Program Private Shared Sub Main(args As String()) Dim ppt As New Presentation("Test.pptx", FileFormat.Pptx2010) Dim chart As IChart = TryCast(ppt.Slides(0).Shapes(0), IChart) chart.Series(2).UseSecondAxis = True chart.SecondaryValueAxis.MajorGridTextLines.FillType = FillFormatType.None ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010) End Sub End Class End Namespace