Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+

TrendlineCollection.Add(ChartTrendlineType) Method

Creates a new trendline of the specified type and adds it to the collection.

Namespace: DevExpress.Spreadsheet.Charts

Assembly: DevExpress.Spreadsheet.v23.1.Core.dll

Declaration

Trendline Add(
    ChartTrendlineType trendlineType
)

Parameters

Name Type Description
trendlineType ChartTrendlineType

A ChartTrendlineType enumeration member that specifies the trendline type.

Returns

Type Description
Trendline

A Trendline object that is the newly added element in the collection.

Example

The following code uses the TrendlineCollection.Add method to display a trendline of the ChartTrendlineType.Polynomial type and customize it.

Trendline - customization

View Example

Worksheet worksheet = workbook.Worksheets["chartTask3"];
workbook.Worksheets.ActiveWorksheet = worksheet;

// Create a chart and specify its location.
Chart chart = worksheet.Charts.Add(ChartType.ScatterMarkers);
chart.SelectData(worksheet["C2:F3"], ChartDataDirection.Row);
chart.TopLeftCell = worksheet.Cells["H2"];
chart.BottomRightCell = worksheet.Cells["N14"];

// Set the minimum and maximum values for the chart value axis.
Axis axis = chart.PrimaryAxes[1];
axis.Scaling.AutoMax = false;
axis.Scaling.AutoMin = false;
axis.Scaling.Min = 0.6;
axis.Scaling.Max = 1.0;
chart.PrimaryAxes[1].MajorGridlines.Visible = false;

// Display a polynomial trendline.
chart.Series[0].Trendlines.Add(ChartTrendlineType.Polynomial);

// Customize the trendline.
Trendline tline = chart.Series[0].Trendlines[0];
tline.DisplayEquation = true;
tline.CustomName = "Trend";
tline.DisplayRSquare = true;
tline.Backward = 1;
tline.Forward = 2;
tline.Outline.SetSolidFill(Color.Red);

The following code snippets (auto-collected from DevExpress Examples) contain references to the Add(ChartTrendlineType) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also