Function Reference

_XLChart_TrendlineSet

Add a new trendline or set properties of an existing trendline of a data series.

#Include <ExcelChart.au3>
_XLChart_TrendlineSet($oObject, $iNumber[, $iType = Default[, $iOption = Default[, $sName = Default]]])

 

Parameters

$oObject Data series object to add or change a trendline
$iNumber Number of the trendline to change or 0 to add a new trendline
$iType Optional: Integer representing the trendline type. Can be any of the XlTrendlineType enumeration (default = Default)
$iOption Optional: Sets trendline option (default = Default). Parameter is only valid for:
$iType = $xlPolynomial. $iOption is interpreted to set property "Order"
$iType = $xlMovingAvg. $iOption is interpreted to set property "Period"
$sName Optional: Name of the trendline. "" deletes the name (default = Default)

 

Return Value

Success: Object identifier of the created/changed trend line
Failure: Returns 0 and sets @error:
    1 - $oObject is no object
    2 - $iNumber is not an integer or < 0
    3 - $iType is not an integer
    4 - Error creating trendline. See @extended for details
    5 - Error accessing the specified trendline. See @extended for details
    6 - Error setting the trendline option (order or period). See @extended for details

 

Remarks

None.

 

Related

 

Example


#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_AU3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=Y
#include-once
#include <ExcelChart.au3>

; *****************************************************************************
; Create example environment
; *****************************************************************************
Global $aExcel = _XLChart_Example(True, 0, -1, -1, -1)
If @error = 2  Then Exit MsgBox(16, "Excel Chart Example Script", "The installed Excel version is not supported by this UDF!" & @CRLF & "Version must be >= 12 (Excel 2007).")
If @error <> 0 Then Exit MsgBox(16, "Excel Chart Example Script", "Error " & @error & " returned by _XLChart_Example on line " & @ScriptLineNumber)

; *****************************************************************************
; Example 1
; Chart 1: Add a trendline to data series 1
; *****************************************************************************
MsgBox(64, "Excel Chart Example Script", "Now changing chart 1 ..." & @CRLF & "Add a trendline to data series 1")
_XLChart_TrendlineSet($aExcel[1].SeriesCollection(1), 0)
If @error Then MsgBox(64, "Excel Chart Example Script", "Error " & @error & " returned by function '_XLChart_TrendlineSet' on line " & @ScriptLineNumber)

; *****************************************************************************
; Example 2
; Chart 1: Change the trendline of data series 1 from linear to polynomial
; *****************************************************************************
MsgBox(64, "Excel Chart Example Script", "Now changing chart 1 ..." & @CRLF & "Change the trendline of data series 1 from linear to polynomial")
_XLChart_TrendlineSet($aExcel[1].SeriesCollection(1), 1, $xlPolynomial)
If @error Then MsgBox(64, "Excel Chart Example Script", "Error " & @error & " returned by function '_XLChart_TrendlineSet' on line " & @ScriptLineNumber)

; *****************************************************************************
; Example 3
; Chart 1: Change the options of trendline 1 plus name of data series 1
; *****************************************************************************
MsgBox(64, "Excel Chart Example Script", "Now changing chart 1 ..." & @CRLF & "Change options and name of the trendline")
_XLChart_TrendlineSet($aExcel[1].SeriesCollection(1), 1, Default, 3, "Testtrendline")
If @error Then MsgBox(64, "Excel Chart Example Script", "Error " & @error & " returned by function '_XLChart_TrendlineSet' on line " & @ScriptLineNumber)

; *****************************************************************************
; Example 4
; Chart 1: Set Weight and color of trendline
; *****************************************************************************
MsgBox(64, "Excel Chart Example Script", "Now changing chart 1 ..." & @CRLF & "Change weight and color of the trendline")
Global $aResult = _XLChart_LineSet($aExcel[1].SeriesCollection(1).Trendlines.Item(1), 2, 0xFF0000)
If @error Then MsgBox(64, "Excel Chart Example Script", "Error " & @error & " returned by function '_XLChart_LineSet' on line " & @ScriptLineNumber)