the loop is in this piece of code:
while(!$ScaleOk)
{
$Scale1 = ( $this->VMax - $this->VMin ) / $Factor;
$Scale2 = ( $this->VMax - $this->VMin ) / $Factor / 2;
$Scale4 = ( $this->VMax - $this->VMin ) / $Factor / 4;
if ( $Scale1 > 1 && $Scale1 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $Divisions = floor($Scale1); $Scale = 1;}
if ( $Scale2 > 1 && $Scale2 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $Divisions = floor($Scale2); $Scale = 2;}
if (!$ScaleOk)
{
if ( $Scale2 > 1 ) { $Factor = $Factor * 10; }
if ( $Scale2 < 1 ) { $Factor = $Factor / 10; }
}
}
try this example:
<?php
$date=array(1204561425,1204621756,1204770143,1204902916,1205035584,
1205171787,1205304588,1205440753,1205573783,1205710193,1205846271,1205979134,1206111811,
1206244544,1206377385,1206510415,1206729711,1206894405,1207044349,1223049892);
$val=array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
include("pChart/pData.class");
include("pChart/pChart.class");
$DataSet = new pData;
$DataSet->AddPoint($val,"Serie1");
$DataSet->AddPoint($date,"Serie2");
$DataSet->AddAllSeries();
$DataSet->RemoveSerie("Serie2");
$DataSet->SetAbsciseLabelSerie("Serie2");
$DataSet->SetSerieName('threads',"Serie1");
$DataSet->SetYAxisName('data');
$DataSet->SetXAxisName('threads');
$DataSet->SetXAxisFormat('date');
$DataSet->SetYAxisFormat('number');
// Initialise the graph
$Test = new pChart(500,250);
$Test->drawGraphAreaGradient(132,153,172,80,TARGET_BACKGROUND);
$FontSize = 8;
$FontName = 'Fonts/tahoma.ttf';
$Test->setFontProperties($FontName,$FontSize);
/*****************************************************************
if you run :
$Test->setGraphArea(49,20,471,151); //=> no infinite loop
******************************************************************/
$Test->setGraphArea(49,20,471,141);
$Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_ADDALL,213,217,221,TRUE,90,0,TRUE);
$Test->drawGraphAreaGradient(162,183,202,80);
$Test->drawGrid(4,TRUE,230,230,230,20);
$Test->setColorPalette(0,191,120,71);
$Test->drawStackedBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),70);
// Render the picture
$Test->Render('image.png');
?>
as in the comment, if you change values of $Test->setGraphArea to (49,20,471,151), no more loop.
if you change some values of the $val array (leaving $Test->setGraphArea(49,20,471,141)), no more loop.
if you want, i have other examples to prove this bug, even with Y serie's values diffents from zero.
Andrea
I've run into a similar problem and have created a patch for this. Simple version: Replace the two 10's in that piece of code with the following: (2 * $MaxDivs)
So it will look like this:
if ( $Scale2 > 1 ) { $Factor = $Factor * (2 * $MaxDivs); }
if ( $Scale2 < 1 ) { $Factor = $Factor / (2 * $MaxDivs); }
Explanation: The automatic scaling can fail in certain combinations of min/max-values on the plot and certain plot heights etc. In my case it was with $VMin = -3.6, $VMax = 5 and $MaxDivs = 5.
The patch:
Index: pChart.class
--- pChart.class (revision 1374)
+++ pChart.class (working copy)
@@ -471,8 +471,8 @@
if ( $Scale2 > 1 && $Scale2 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $Divisions = floor($Scale2); $Scale = 2;}
if (!$ScaleOk)
{
- if ( $Scale2 > 1 ) { $Factor = $Factor * 10; }
- if ( $Scale2 < 1 ) { $Factor = $Factor / 10; }
+ if ( $Scale2 > 1 ) { $Factor = $Factor * (2 * $MaxDivs); }
+ if ( $Scale2 < 1 ) { $Factor = $Factor / (2 * $MaxDivs); }
}
}
This can be very easy fixed with checking that VMax is not equal to VMin:
after line 351 (for Version 1.27b) add this
if ($this->VMax == $this->VMin) { $this->VMin = 0; }
That will fix the problem.
I had the same problem and here is my solution.
In the drawScale function in the /* Compute automatic scaling */ section there are two if statements, that allow an exit from infinity. These are
if ( $Scale1 > 1 && $Scale1 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $Divisions = floor($Scale1); $Scale = 1;}
if ( $Scale2 > 1 && $Scale2 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $Divisions = floor($Scale2); $Scale = 2;}
If you add another one with
if ( $Scale4 > 1 && $Scale4 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $Divisions = floor($Scale4); $Scale = 4;}
you should get out of there. Works fine for me...
John