Add method (Excel Graph)
Creates a new trendline. Returns a Trendline object.
expression.Add (Type, Order, Period, Forward, Backward, Intercept, DisplayEquation, DisplayRSquared, Name)
expression Required. An expression that returns a Trendline object.
Name | Required/Optional | Data type | Description |
---|---|---|---|
Type | Optional | XlTrendlineType | The type of trendline. Can be one of the XlTrendlineType constants. |
Order | Optional | Variant | Required if Type is xlPolynomial. The trendline order. Must be an integer from 2 through 6. |
Period | Optional | Variant | Required if Type is xlMovingAvg. The trendline period. Must be an integer greater than 1 and less than the number of data points in the series you are adding a trendline to. |
Forward | Optional | Variant | The number of periods (or units on a scatter chart) that the trendline extends forward. |
Backward | Optional | Variant | The number of periods (or units on a scatter chart) that the trendline extends backward. |
Intercept | Optional | Variant | The trendline intercept. If this argument is omitted, the intercept is automatically set by the regression. |
DisplayEquation | Optional | Variant | True to display the equation of the trendline on the chart (in the same data label as the R-squared value). The default value is False. |
DisplayRSquared | Optional | Variant | True to display the R-squared value of the trendline on the chart (in the same data label as the equation). The default value is False. |
Name | Optional | Variant | The name of the trendline, as text. If this argument is omitted, Graph generates a name. |
This example creates a new linear trendline on the chart.
myChart.SeriesCollection(1).Trendlines.Add
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.