26 self::TREND_LOGARITHMIC,
27 self::TREND_EXPONENTIAL,
37 self::TREND_POLYNOMIAL_2,
38 self::TREND_POLYNOMIAL_3,
39 self::TREND_POLYNOMIAL_4,
40 self::TREND_POLYNOMIAL_5,
41 self::TREND_POLYNOMIAL_6,
51 public static function calculate($trendType = self::TREND_BEST_FIT, $yValues = [], $xValues = [], $const =
true)
54 $nY = count($yValues);
55 $nX = count($xValues);
59 $xValues = range(1, $nY);
60 } elseif ($nY !== $nX) {
62 trigger_error(
'Trend(): Number of elements in coordinate arrays do not match.', E_USER_ERROR);
65 $key = md5($trendType . $const . serialize($yValues) . serialize($xValues));
69 case self::TREND_LINEAR:
70 case self::TREND_LOGARITHMIC:
71 case self::TREND_EXPONENTIAL:
72 case self::TREND_POWER:
73 if (!isset(self::$trendCache[
$key])) {
74 $className =
'\PhpOffice\PhpSpreadsheet\Shared\Trend\\' . $trendType .
'BestFit';
75 self::$trendCache[
$key] =
new $className($yValues, $xValues, $const);
78 return self::$trendCache[
$key];
79 case self::TREND_POLYNOMIAL_2:
80 case self::TREND_POLYNOMIAL_3:
81 case self::TREND_POLYNOMIAL_4:
82 case self::TREND_POLYNOMIAL_5:
83 case self::TREND_POLYNOMIAL_6:
84 if (!isset(self::$trendCache[$key])) {
85 $order = substr($trendType, -1);
89 return self::$trendCache[
$key];
90 case self::TREND_BEST_FIT:
91 case self::TREND_BEST_FIT_NO_POLY:
96 foreach (self::$trendTypes as $trendMethod) {
97 $className =
'\PhpOffice\PhpSpreadsheet\Shared\Trend\\' . $trendType .
'BestFit';
98 $bestFit[$trendMethod] =
new $className($yValues, $xValues, $const);
99 $bestFitValue[$trendMethod] = $bestFit[$trendMethod]->getGoodnessOfFit();
101 if ($trendType != self::TREND_BEST_FIT_NO_POLY) {
102 foreach (self::$trendTypePolynomialOrders as $trendMethod) {
103 $order = substr($trendMethod, -1);
105 if ($bestFit[$trendMethod]->getError()) {
106 unset($bestFit[$trendMethod]);
108 $bestFitValue[$trendMethod] = $bestFit[$trendMethod]->getGoodnessOfFit();
113 arsort($bestFitValue);
114 $bestFitType = key($bestFitValue);
116 return $bestFit[$bestFitType];
static calculate($trendType=self::TREND_BEST_FIT, $yValues=[], $xValues=[], $const =true)
static $trendTypePolynomialOrders
const TREND_BEST_FIT_NO_POLY