Menu

Max execution time - pChart.class on line 467

Help
fish77
2009-03-17
2018-09-20
  • fish77

    fish77 - 2009-03-17

    Maybe someone can help me, I have a real strange problem.

    When I run the code below I get the following error:
    Fatal error: Maximum execution time of 30 seconds exceeded in ..../pChart/pChart.class on line 467

    If I replace the first amount in $DataSet "Serie1" from 19381.45 to 15381.45 or 45381.45 it will work but if
    the value is 19381.45 it gives me the max ecexution time error. Hopefully anyone can help me.

    Code:

      // Dataset definition  
      $DataSet = new pData; 
      $DataSet->AddPoint(array("19381.45","12465.25","10061.15"),"Serie1"); 
      $DataSet->AddPoint(array("461.46","311.63","479.10"),"Serie2"); 
      $DataSet->AddPoint(array("1","2","3"),"Serie3");
      $DataSet->AddSerie("Serie1"); 
      $DataSet->SetAbsciseLabelSerie("Serie3"); 
      $DataSet->SetSerieName("Monthly Income","Serie1"); 
      $DataSet->SetSerieName("Average per Order","Serie2"); 
      
      // Initialise the graph 
      $Test = new pChart(320,190); 
      $Test->drawGraphAreaGradient(90,90,90,90,TARGET_BACKGROUND); 
      
      // Prepare the graph area 
      $Test->setFontProperties("Fonts/tahoma.ttf",8); 
      $Test->setGraphArea(270,40,60,150);   
      
      // Initialise graph area 
      $Test->setFontProperties("Fonts/tahoma.ttf",8); 
      
      // Draw the 1st graph 
      $DataSet->SetYAxisName("Monthly Income"); 
      $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,213,217,221,TRUE,0,0); 
      $Test->drawGraphAreaGradient(40,40,40,-50); 
      $Test->drawGrid(4,TRUE,230,230,230,10); 
      $Test->setShadowProperties(3,3,0,0,0,30,4); 
      $Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription()); 
      $Test->clearShadow(); 
      $Test->drawFilledCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription(),.1,30); 
      $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,254,254,254); 
      
      // Clear the scale 
      $Test->clearScale(); 
      
      // Draw the 2nd graph 
      $DataSet->RemoveSerie("Serie1"); 
      $DataSet->AddSerie("Serie2"); 
      $DataSet->SetYAxisName("Average per Order"); 
      $Test->drawRightScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,213,217,221,TRUE,0,0); 
      $Test->drawGrid(4,TRUE,230,230,230,10); 
      $Test->setShadowProperties(3,3,0,0,0,30,4); 
      $Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription()); 
      $Test->clearShadow(); 
      $Test->drawFilledCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription(),.1,30); 
      $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,254,254,254); 
      
      // Write the legend (box less) 
      $Test->setFontProperties("Fonts/tahoma.ttf",8); 
      $Test->drawLegend(180,3,$DataSet->GetDataDescription(),0,0,0,0,0,0,254,254,254,FALSE); 
      $Test->drawTitle(30,410,"Months",254,254,254,300,30,TRUE);      
      
      // Write the title 
      $Test->setFontProperties("Fonts/FreeSansBold.ttf",12); 
      $Test->setShadowProperties(1,1,0,0,0); 
      $Test->drawTitle(-195,0,"Sales ".$year,254,254,254,300,30,TRUE); 
      $Test->clearShadow(); 
      
      // Render the picture 
      $Test->Render("chart3.png"); 

    Thanks.

     
    • fish77

      fish77 - 2009-03-17

      I forgot to say I using the latest version pChart.1.27d.rar

       
      • Mike DeCook

        Mike DeCook - 2009-03-30

        I am having this same problem, however it seems to be inconsistent and somewhat related to the values that are entered.  If I have several series with several high values I don't get an error, but if I have one or two series with low values then it seems to timeout. 

        $Test->setGraphArea(20,15,285,120);

         
    • fish77

      fish77 - 2009-03-18

      As I found out, the height of the chart is to small. If I increase the height of the chart from 150 pixels to 160 pixels it will work.

       
  • Skye Bender-deMoll

    I'm having a similar problem, charts with certain values cause it to hang during drawScale() method.   Like array(0,0,0,0,0,57000); hangs but array(0,0,0,0,0,56000);  executes instantly.  When I increase the size of the graph area by increasing the vertical dimensions of setGraphArea() by a factor of 10, it runs fine.  So it seems like it is some sort of division or scaling error?  If the difference between the scale of the data and the pixels is too large it crashes.   Pain it the butt, probably have to change libraries.

     
  • Skye Bender-deMoll

    Ok, the bug is in the drawScale method.  Around line 480, it is trying to calculate an appropriate scale range inside of a while loop. If it doesn't get a good value, it increases the scale factor by 10x and tries again. …. unless the it is below 1, in which case it decreases by 10x… so for some values it gets stuck in an infinite loop oscillating between the same values.

    Hackish work around:

    change from:
    if ( $Scale2 > 1 ) { $Factor = $Factor * 10; }
    if ( $Scale2 < 1 ) { $Factor = $Factor / 10; }

    to:

    if ( $Scale2 > 1 ) { $Factor = $Factor * 10; }
    if ( $Scale2 < 1 ) { $Factor = $Factor / 15; }

    since it isn't increasing and decreasing by the same value, it should eventually converge.  Negative side effect: sometimes the scale values won't be nice round numbers, end up with 1033333 etc.   Also, loop conditions may still be possible for some values, so I added a max loop param of 100 and an error message so at least it should break the loop.

     
  • f-itoh

    f-itoh - 2010-08-13

    this is my patch. around line 480. it works for me.

        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 ( $Scale1 == $this->VMax && $Factor == 1 && !$ScaleOk) { $ScaleOk = TRUE; $Scale = 1; };

     
  • Anonymous

    Anonymous - 2010-10-12

    I wish to confirm that this is indeed the solution to my problem. 

    Adding here:  processor hangs in case anyone else searches for the term.

    Thanks for your help.

     
  • Dmitry

    Dmitry - 2018-09-20

    Infinit loop when graph area heigh smaller than some value.
    This works fine:
    Add this before while on 473:
    $i = 0;
    And this in while body:
    If ($i++ == 100)
    {
    $ScaleOk = TRUE;
    $Divisions = 1;
    $Scale = 2;
    }

     

Log in to post a comment.

MongoDB Logo MongoDB