Re: Division by zero error
Hi,
Here's another division by zero.
(I posted this elswhere and thought it'd be good to have it here)
It triggers upon using writeLabel() function. I'm running pChart 2.1.1.
It's on line 2750, in the file: pDraw.class.php.
(No labels display, even after turning off the warnings)
I'm just drawing a line chart, and needed some labels.
Code:
if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
{
$Height = ($this->GraphAreaY2 - $this->GraphAreaY1) - $Data["Axis"][$AxisID]["Margin"]*2;
$ScaleHeight = $Data["Axis"][$AxisID]["ScaleMax"] - $Data["Axis"][$AxisID]["ScaleMin"];
$Step = $Height / $ScaleHeight;
if ( $ReturnOnly0Height )
{ foreach($Values as $Key => $Value) { if ( $Value == VOID ) { $Result[] = VOID; } else { $Result[] = $Step * $Value; } } }
else
{ foreach($Values as $Key => $Value) { if ( $Value == VOID ) { $Result[] = VOID; } else { $Result[] = $this->GraphAreaY2 - $Data["Axis"][$AxisID]["Margin"] - ($Step * ($Value-$Data["Axis"][$AxisID]["ScaleMin"])); } } }
}
else
{
$Width = ($this->GraphAreaX2 - $this->GraphAreaX1) - $Data["Axis"][$AxisID]["Margin"]*2;
$ScaleWidth = $Data["Axis"][$AxisID]["ScaleMax"] - $Data["Axis"][$AxisID]["ScaleMin"];
$Step = $Width / $ScaleWidth;
if ( $ReturnOnly0Height )
{ foreach($Values as $Key => $Value) { if ( $Value == VOID ) { $Result[] = VOID; } else { $Result[] = $Step * $Value; } } }
else
{ foreach($Values as $Key => $Value) { if ( $Value == VOID ) { $Result[] = VOID; } else { $Result[] = $this->GraphAreaX1 + $Data["Axis"][$AxisID]["Margin"] + ($Step * ($Value-$Data["Axis"][$AxisID]["ScaleMin"])); } } }
}
Line 2750 is: $Step = $Width / $ScaleWidth;
(After hack attempts on the class, it appears pChart is having a tough time positioning the labels correctly.)
Thank you!
Greg