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; }