How to set same number of intervals for Primary and Secondary ValueAxis in WinForms Presentation?
​The PowerPoint framework is a feature rich .NET PowerPoint class library that can be used by developers to create, read, edit and convert PowerPoint files to PDFs and images programmatically without Office or interop dependencies. Using this library, you can set same number of intervals for the PrimaryValue Axis and SecondaryValue Axis in the chart in the Presentation document.
Steps to set the same number of intervals for the Primary and Secondary Value Axis in the chart using C# and VB.NET:
- Create a new C# console application project.
- Install the Syncfusion.Presentation.WinForms NuGet package as a reference to your .NET Framework applications from NuGet.org
- Include the following namespace in the Program.cs file.
C#
using Syncfusion.Presentation; using Syncfusion.OfficeChart;
VB
Imports Syncfusion.Presentation Imports Syncfusion.OfficeChart
- Use the following code example to set the same number of intervals for the PrimaryValue Axis and SecondaryValue Axis in the chart.
C#
//Create an instance of the IPresentation. using (IPresentation pptxDoc = Presentation.Create()) { //Create a new slide. ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank); //Add a new chart to the slide by specifying its position and size as parameters. IPresentationChart chart = slide.Charts.AddChart(100, 80, 500, 350); chart.ChartTitle = "Sales comparison"; chart.ChartTitleArea.Bold = true; //Set the data for the chart– RowIndex, columnIndex and data. chart.ChartData.SetValue(1, 1, "Month"); chart.ChartData.SetValue(2, 1, "July"); chart.ChartData.SetValue(3, 1, "August"); chart.ChartData.SetValue(4, 1, "September"); chart.ChartData.SetValue(5, 1, "October"); chart.ChartData.SetValue(6, 1, "November"); chart.ChartData.SetValue(7, 1, "December"); chart.ChartData.SetValue(1, 2, "2013"); chart.ChartData.SetValue(2, 2, 35); chart.ChartData.SetValue(3, 2, 47); chart.ChartData.SetValue(4, 2, 30); chart.ChartData.SetValue(5, 2, 29); chart.ChartData.SetValue(6, 2, 25); chart.ChartData.SetValue(7, 2, 30); chart.ChartData.SetValue(1, 3, "2014"); chart.ChartData.SetValue(2, 3, 30); chart.ChartData.SetValue(3, 3, 25); chart.ChartData.SetValue(4, 3, 29); chart.ChartData.SetValue(5, 3, 35); chart.ChartData.SetValue(6, 3, 38); chart.ChartData.SetValue(7, 3, 32); //Create a new series with the name. IOfficeChartSerie serie2013 = chart.Series.Add("2013"); //Set the data range of the chart series to start row, start column, end row, end column. serie2013.Values = chart.ChartData[2, 2, 7, 2]; serie2013.SerieType = OfficeChartType.Column_Clustered; IOfficeChartSerie serie2014 = chart.Series.Add("2014"); serie2014.Values = chart.ChartData[2, 3, 7, 3]; serie2014.SerieType = OfficeChartType.Line; //Use the Secondary Axis. serie2014.UsePrimaryAxis = false; //Set the maximum value of the interval in the primary value axis. chart.PrimaryValueAxis.MaximumValue = 50; //Set the maximum value of the interval in the secondary value axis. chart.SecondaryValueAxis.MaximumValue = 50; //Save the PowerPoint Presentation as stream. FileStream outputStream = new FileStream("Output.pptx", FileMode.Create); pptxDoc.Save(outputStream); outputStream.Close(); }
VB
'Create an instance of the IPresentation. Using pptxDoc As IPresentation = Presentation.Create 'Create a new slide. Dim slide As ISlide = pptxDoc.Slides.Add(SlideLayoutType.Blank) 'Add a new chart to the slide by specifying its position and size as parameters. Dim chart As IPresentationChart = slide.Charts.AddChart(100, 80, 500, 350) chart.ChartTitle = "Sales comparison" chart.ChartTitleArea.Bold = True 'Set the data for the chart_ RowIndex, columnIndex and data. chart.ChartData.SetValue(1, 1, "Month") chart.ChartData.SetValue(2, 1, "July") chart.ChartData.SetValue(3, 1, "August") chart.ChartData.SetValue(4, 1, "September") chart.ChartData.SetValue(5, 1, "October") chart.ChartData.SetValue(6, 1, "November") chart.ChartData.SetValue(7, 1, "December") chart.ChartData.SetValue(1, 2, "2013") chart.ChartData.SetValue(2, 2, 35) chart.ChartData.SetValue(3, 2, 47) chart.ChartData.SetValue(4, 2, 30) chart.ChartData.SetValue(5, 2, 29) chart.ChartData.SetValue(6, 2, 25) chart.ChartData.SetValue(7, 2, 30) chart.ChartData.SetValue(1, 3, "2014") chart.ChartData.SetValue(2, 3, 30) chart.ChartData.SetValue(3, 3, 25) chart.ChartData.SetValue(4, 3, 29) chart.ChartData.SetValue(5, 3, 35) chart.ChartData.SetValue(6, 3, 38) chart.ChartData.SetValue(7, 3, 32) 'Create a new series with the name. Dim serie2013 As IOfficeChartSerie = chart.Series.Add("2013") 'Set the data range of the chart series to start row, start column, end row, end column. serie2013.Values = chart.ChartData(2, 2, 7, 2) serie2013.SerieType = OfficeChartType.Column_Clustered Dim serie2014 As IOfficeChartSerie = chart.Series.Add("2014") serie2014.Values = chart.ChartData(2, 3, 7, 3) serie2014.SerieType = OfficeChartType.Line 'Use the Secondary Axis. serie2014.UsePrimaryAxis = False 'Set the maximum value of the interval in the primary value axis. chart.PrimaryValueAxis.MaximumValue = 50 'Set the maximum value of the interval in the secondary value axis. chart.SecondaryValueAxis.MaximumValue = 50 'Save the PowerPoint Presentation as stream. Dim outputStream As FileStream = New FileStream("Output.pptx", FileMode.Create) pptxDoc.Save(outputStream) outputStream.Close() End Using
A complete working sample to set the same number of intervals for the PrimaryValue Axis and SecondaryValue Axis in the chart in presentation using C# can be downloaded from here.
By executing the program, you will get the PowerPoint document as follows.
Explore more about the rich set of Syncfusion PowerPoint Framework features.
See also:
Working with charts in Presentation
Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering a Syncfusion license key in your application to use the components without a trail message.
Conclusion
I hope you enjoyed learning about how to change the foreground and background in UWP.
You can refer to our WinForms Power Point feature tour page
to know about its other groundbreaking feature representations documentation
and how to quickly get started for configuration
specifications. You can also explore our WinForms Power Point example
to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!