In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how to add trend lines to the PPT chart in C#, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.
Chart types that support trend lines include 2D area chart, bar chart, bar chart, column chart, stock price chart, xy (scatter chart) and bubble chart; trend lines cannot be added to the data series of 3D, stacking, radar, pie, surface, or donut charts. There are six types of trend lines that can be added, namely, Polynomial trend line, Exponential trend line, Linear trend line, Logarithmic trend line, Power trend line and moving average trend line. Let's take a column chart as an example to add trend lines. The methods and steps are referred to as follows.
Program environment:
Visual Studio 2017
.net framework 4.6.1
Power Point 2013 (.pptx)
PPT Class Library: Spire.Presentation for .NET
First, the realization method
Add the trend line by calling the method AddTrendLine (TrendlinesType type) provided by the Itrendline interface in Spire.Presentation.dll. Before editing the code, follow the method in point 2 below to add the reference Spire.Presentation.dll to the program.
II. Installation of PPT class library
About PPT class library installation: you can install to the program directly through Nuget search. The specific methods are as follows:
Right-click "references", "manage Nuget packages", and then follow the steps in the following figure
Complete the installation:
Code implementation 1. C#using Spire.Presentation;using Spire.Presentation.Charts;namespace AddTrendline {class Program {static void Main (string [] args) {/ / create an instance of the Presentation class Presentation ppt = new Presentation (); / / load the PowerPoint document ppt.LoadFromFile ("test.pptx") / / get the first slide ISlide slide = ppt.Slides [0]; / / get the first chart on the slide IChart chart = (IChart) slide.Shapes [0]; / / add a linear trend line ITrendlines trendLine = chart.Series [0] .AddTrendLine (TrendlinesType.Polynomial) to the first data series of the chart / / polynomial trend line / / ITrendlines trendLine = chart.Series [0] .AddTrendline (TrendlinesType.Exponential); / / Index trend line / / ITrendlines trendLine = chart.Series [0] .AddTrendline (TrendlinesType.Linear); / / Linear trend line / / ITrendlines trendLine = chart.Series [0] .AddTrendline (TrendlinesType.Logarithmic); / / logarithmic trend line / / ITrendlines trendLine = chart.Series [0] .AddTrendline (TrendlinesType.Power) / / Power trend line / / ITrendlines trendLine = chart.Series [0] .AddTrendline (TrendlinesType.MovingAverage); / / moving average trend line / / display formula trendLine.displayEquation = true; / / display R square value trendLine.displayRSquaredValue = true; / / Save the resulting document ppt.SaveToFile ("AddTrendline.pptx", FileFormat.Pptx2013) System.Diagnostics.Process.Start ("AddTrendline.pptx");}
Trend line addition effect:
2 、 Vb.netImports Spire.PresentationImports Spire.Presentation.ChartsNamespace AddTrendline Class Program Private Shared Sub Main (args As String ()) 'create an instance of Presentation class Dim ppt As New Presentation ()' load PowerPoint document ppt.LoadFromFile ("test.pptx") 'get the first slide Dim slide As ISlide = ppt.Slides (0) 'get the first chart on the slide Dim chart As IChart = DirectCast (slide.Shapes (0)) IChart) 'add a linear trend line Dim trendLine As ITrendlines = chart.Series (0) .AddTrendLine (TrendlinesType.Polynomial)' polynomial trendline'to the first data series of the chart ITrendlines trendLine = chart.Series [0] .AddTrendLine (TrendlinesType.Exponential) 'exponential trend line' ITrendlines trendLine = chart.Series [0] .AddTrendline (TrendlinesType.Linear); 'linear trend line' ITrendlines trendLine = chart.Series [0] .AddTrendline (TrendlinesType.Logarithmic); 'logarithmic trend line' ITrendlines trendLine = chart.Series [0] .AddTrendline (TrendlinesType.Power); 'power trendline' ITrendlines trendLine = chart.Series [0] .AddTrendLine (TrendlinesType.MovingAverage) 'moving average trend line 'display formula trendLine.displayEquation = True' display R square value trendLine.displayRSquaredValue = True 'save the resulting document ppt.SaveToFile ("AddTrendline.pptx" FileFormat.Pptx2013) System.Diagnostics.Process.Start ("AddTrendline.pptx") End Sub End ClassEnd Namespace thank you for reading this article carefully. I hope the article "how to add trend lines to the PPT chart in C#" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.