Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Problem z wykresem, jw
miras
post
Post #1





Grupa: Zarejestrowani
Postów: 1 004
Pomógł: 9
Dołączył: 18.01.2011
Skąd: Siedlce

Ostrzeżenie: (30%)
XX---


Witam, mam skrypt, który zlicza ilość graczy z serwera w danych godzinach i potem na podstawie tych danych generuje wykres, wszystko działa - problem pojawia się gdy wszystkie wartości są takie same - czyli np. 1, 1, 1, 1, 1, 1, 1 itp.

Błąd jaki mi wyrzuca to Division by zero - dzielenie przez zero czy coś w tym stylu.


błędy w linijkach: 32, 40, 62

  1. <?php
  2. class LabChartsLine extends LabCharts {
  3.  
  4. private $min;
  5. private $max;
  6.  
  7. public function __construct () {
  8. $this->_type = 'lc';
  9. $this->_colors = 'FAAC02';
  10. $this->_size = '300x150';
  11. }
  12. protected function dataToString ($data) {
  13. $str = 't:';
  14. $this->max = max($data);
  15. $this->min = min($data);
  16.  
  17. foreach ($data as $value) {
  18. if ($this->max != $this->min) {
  19. $newValue = round((1 - ($this->max - $value) / ($this->max - $this->min)) * 100, 3);
  20. $str .= $newValue . ',';
  21. } else {
  22. $newValue = round($this->max * 100, 3);
  23. $str .= $newValue . ',';
  24. }
  25. }
  26. return substr($str, 0, -1);
  27. }
  28.  
  29. public function setAxis ($rangeY, $labelsX) {
  30. if ($this->max != $this->min) {
  31. $newRange = round($rangeY / ($this->max - $this->min) * 100, 3);
  32. } else {
  33. $newRange = round($this->min * 100, 3);
  34. }
  35. $strLabels = '0:';
  36. $strPosition = '0';
  37. for ($a = $this->getFirstOfRange($rangeY); $a <= $this->max; $a += $rangeY) {
  38. $strLabels .= '|' . $a;
  39. }
  40. for ($a = $this->getFirstGrid($rangeY); $a <= 100; $a += $newRange) {
  41. $strPosition .= ',' . $a;
  42. }
  43. $this->_axis = 'y,x';
  44. $this->_axisRange = $strLabels . '|1:|' . $labelsX;
  45. $this->_axisPosition = $strPosition;
  46. }
  47.  
  48. public function setGrids ($rangeY) {
  49. if ($this->max != $this->min) {
  50. $newRangeY = round($rangeY / ($this->max - $this->min) * 100, 3);
  51. $newRangeX = round(100 / (count($this->baseData) - 1), 2);
  52. } else {
  53. $newRangeY = round($rangeY / $this->min * 100, 3);
  54. $newRangeX = round(100 / (count($this->baseData) - 1), 2);
  55. }
  56. $this->_grids = $newRangeX . ',' . $newRangeY . ',3,3,0,' . $this->getFirstGrid($rangeY);
  57. }
  58.  
  59. private function getFirstGrid($rangeY) {
  60. if ($this->max != $this->min) {
  61. return round((1 - ($this->max - $this->getFirstOfRange($rangeY)) / ($this->max - $this->min)) * 100, 3);
  62. } else {
  63. return round((1 - ($this->max - $this->getFirstOfRange($rangeY)) / $this->min) * 100, 3);
  64. }
  65. }
  66.  
  67. private function getFirstOfRange($rangeY){
  68. for ($pierwszyPodzielny = $this->min; $pierwszyPodzielny <= $this->max; $pierwszyPodzielny++){
  69. if (abs($pierwszyPodzielny) % $rangeY == 0 || $pierwszyPodzielny == 0)
  70. break;
  71. }
  72. return $pierwszyPodzielny;
  73. }
  74.  
  75. }
  76.  
  77. ?>
  78.  



mógłby ktoś mi podpowiedzieć jak temu zaradzić ? jeżeli wszystkie wartości są takie same to na wykresie powinna się pojawić pozioma linia i tyle.

Dzięki z góry!

Ten post edytował miras 4.12.2014, 18:22:01


--------------------
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.08.2025 - 15:19