ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Adding TrendLine (https://www.excelbanter.com/excel-programming/274942-adding-trendline.html)

Wilhelmina Maloles

Adding TrendLine
 
I am writing an application in C# that will send the
results to an Excel spreadsheet. The Excel spreadsheet
will contain the tabulated results and charts.

For one chart, there are four series. The chart type for
the first series is Excel.XlChartType.xlColumnClustered.
This is the one that I need to add the trendline to. I
have seen some VB code that add the trend line as follows:

Worksheets("sheet1").ChartObjects(1).Chart.SeriesC ollection
(1).Trendlines.Add type:=xlLinear, name:="Linear Trend"

I can't find the same Add function in C#. When I try to
use the following code:

Excel.Series oSeries = (Excel.Series)
oChart.SeriesCollection(1);
oSeries.Trendlines.Add(Excel.XlTrendlineType.xlPol ynomial,
2, null, null, null, null, null, null);

I get the following compile error:

'Excel.Series.Trendlines(object)' denotes a 'method' which
is not valid in the given context

How do I add a trend line in C#?




All times are GMT +1. The time now is 09:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com