Adding TrendLine

W

Wilhelmina Maloles

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.SeriesCollection
(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.xlPolynomial,
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#?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top