Skip to content

Commit 1dbd0f9

Browse files
committed
Fixed a couple of issues with GetLinearRegression().
1 parent 54b942f commit 1dbd0f9

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

chart/flex_forms_chart.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public static function FieldType(&$state, $num, &$field, $id)
123123
}
124124
}
125125

126-
function GetLinearRegression($xvals, $yvals, $calcpoints = true)
126+
public static function GetLinearRegression($xvals, $yvals, $calcpoints = true)
127127
{
128128
// Calculate: y = a + bx
129129
// Where:
@@ -160,7 +160,8 @@ function GetLinearRegression($xvals, $yvals, $calcpoints = true)
160160

161161
$b = $Sxy / $Sxx;
162162
$a = ($Ey - ($b * $Ex)) / $n;
163-
$r = $Sxy / sqrt($Sxx * $Syy);
163+
$r = sqrt($Sxx * $Syy);
164+
$r = ($r == 0 ? 1 : $Sxy / $r);
164165

165166
if (!$calcpoints) $points = false;
166167
else

0 commit comments

Comments
 (0)