29 require_once PHPEXCEL_ROOT .
'PHPExcel/Shared/trend/linearBestFitClass.php';
30 require_once PHPEXCEL_ROOT .
'PHPExcel/Shared/trend/logarithmicBestFitClass.php';
31 require_once PHPEXCEL_ROOT .
'PHPExcel/Shared/trend/exponentialBestFitClass.php';
32 require_once PHPEXCEL_ROOT .
'PHPExcel/Shared/trend/powerBestFitClass.php';
33 require_once PHPEXCEL_ROOT .
'PHPExcel/Shared/trend/polynomialBestFitClass.php';
63 self::TREND_LOGARITHMIC,
64 self::TREND_EXPONENTIAL,
73 self::TREND_POLYNOMIAL_3,
74 self::TREND_POLYNOMIAL_4,
75 self::TREND_POLYNOMIAL_5,
76 self::TREND_POLYNOMIAL_6
87 public static function calculate($trendType=self::TREND_BEST_FIT, $yValues, $xValues=
array(), $const=True) {
89 $nY = count($yValues);
90 $nX = count($xValues);
94 $xValues =
range(1,$nY);
96 } elseif ($nY != $nX) {
98 trigger_error(
"trend(): Number of elements in coordinate arrays do not match.", E_USER_ERROR);
101 $key = md5($trendType.$const.serialize($yValues).serialize($xValues));
103 switch ($trendType) {
105 case self::TREND_LINEAR :
106 case self::TREND_LOGARITHMIC :
107 case self::TREND_EXPONENTIAL :
108 case self::TREND_POWER :
109 if (!isset(self::$_trendCache[
$key])) {
110 $className =
'PHPExcel_'.$trendType.
'_Best_Fit';
111 self::$_trendCache[
$key] =
new $className($yValues,$xValues,$const);
113 return self::$_trendCache[
$key];
115 case self::TREND_POLYNOMIAL_2 :
116 case self::TREND_POLYNOMIAL_3 :
117 case self::TREND_POLYNOMIAL_4 :
118 case self::TREND_POLYNOMIAL_5 :
119 case self::TREND_POLYNOMIAL_6 :
120 if (!isset(self::$_trendCache[$key])) {
121 $order = substr($trendType,-1);
124 return self::$_trendCache[
$key];
126 case self::TREND_BEST_FIT :
127 case self::TREND_BEST_FIT_NO_POLY :
130 foreach(self::$_trendTypes as $trendMethod) {
131 $className =
'PHPExcel_'.$trendMethod.
'BestFit';
132 $bestFit[$trendMethod] =
new $className($yValues,$xValues,$const);
133 $bestFitValue[$trendMethod] = $bestFit[$trendMethod]->getGoodnessOfFit();
135 if ($trendType != self::TREND_BEST_FIT_NO_POLY) {
136 foreach(self::$_trendTypePolyOrders as $trendMethod) {
137 $order = substr($trendMethod,-1);
139 if ($bestFit[$trendMethod]->getError()) {
140 unset($bestFit[$trendMethod]);
142 $bestFitValue[$trendMethod] = $bestFit[$trendMethod]->getGoodnessOfFit();
147 arsort($bestFitValue);
148 $bestFitType = key($bestFitValue);
149 return $bestFit[$bestFitType];
const TREND_BEST_FIT_NO_POLY
static calculate($trendType=self::TREND_BEST_FIT, $yValues, $xValues=array(), $const=True)
static $_trendTypePolyOrders
Create styles array
The data for the language used.