跳到主要内容

TREND

Returns numbers in a linear trend matching known data points, using the least squares method.

Syntax

expression.TREND(arg1, arg2, arg3, arg4);

expression - A variable that represents a ApiWorksheetFunction class.

Parameters

NameRequired/OptionalData typeDefaultDescription
arg1RequiredApiRange | ApiName | number[]A range or array of y-values from the <em>y = mx + b</em> equation.
arg2OptionalApiRange | ApiName | number[]An optional range or array of x-values from the <em>y = mx + b</em> equation, an array of the same size as an array of y-values.
arg3OptionalApiRange | ApiName | number[]A range or array of new x-values for which this function will return corresponding y-values.
arg4OptionalApiRange | ApiName | booleanA logical value: the constant <em>b</em> is calculated normally if this parameter is set to -true or omitted,\ and <em>b</em> is set equal to 0 if the parameter is -false.

Returns

number

Example

let worksheet = Api.GetActiveSheet();
let func = Api.GetWorksheetFunction();
let month = ["Month", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let sales = ["Sales", "$1,500.00", "$1,230.00", "$1,700.00", "$1,000.00", "$980.00", "$1,470.00", "$1,560.00", "$1,640.00", "$1,420.00", "$1,100.00"];

for (let i = 0; i < month.length; i++) {
worksheet.GetRange("A" + (i + 1)).SetValue(month[i]);
}
for (let j = 0; j < sales.length; j++) {
worksheet.GetRange("B" + (j + 1)).SetValue(sales[j]);
}

worksheet.GetRange("C1").SetValue("Trend");
let range1 = worksheet.GetRange("B2:B11");
let range2 = worksheet.GetRange("A2:A11");
worksheet.GetRange("C2:C11").SetValue(func.TREND(range1, range2));