#5 Error when all data is same value.

open
nobody
None
5
2004-03-26
2004-03-26
No

I was unable to draw a simple line graph when i
submitted an array where the data was "1, 1, 1, 1, 1".
The error

Division by zero in panachart.php on line 257

occured. This was just on a test system so i wont be
affected by it later but took me a while to under stand
what was wrong.

Simply changing the data to "1, 2, 1, 1, 1" prevented
the error from happening and the graph was drawn.

Discussion

  • Nobody/Anonymous

    Logged In: NO

    I had the same thing happen to me. I added some code to
    the panachart.php page. I put this code starting on line 217:

    if($min == $max)
    {
    $min = $max - ($max / 2);
    $max = $max + ($max / 8);
    }

    This fixed it for my implementation, but you might have to
    modify the '2' and the '8' to make the data fill up the graphs
    more.

    Any questions, email me...
    cnuss.nospam@emaple.nospam.net (Remove the ".nospam"
    items in the email address of course)

     
  • Stephen Menton

    Stephen Menton - 2006-10-11

    Logged In: YES
    user_id=1617945

    the anonymous poster is on the right track but you can still
    get div zero errors if all fields contain 0. you can catch
    that using the following:

    if( $min == $max ) {
    if( $min == 0 ) {
    $max = 1;
    } else {
    $min = $max - ($max / 2);
    $max = $max + ($max / 8);
    }
    }

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks