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
<?php
class LabChartsLine extends LabCharts {
private $min;
private $max;
public function __construct () {
$this->_type = 'lc';
$this->_colors = 'FAAC02';
$this->_size = '300x150';
}
protected function dataToString ($data) {
$str = 't:';
foreach ($data as $value) {
if ($this->max != $this->min) {
$newValue = round((1
- ($this->max - $value) / ($this->max - $this->min)) * 100
, 3
); $str .= $newValue . ',';
} else {
$newValue = round($this->max * 100
, 3
); $str .= $newValue . ',';
}
}
}
public function setAxis ($rangeY, $labelsX) {
if ($this->max != $this->min) {
$newRange = round($rangeY / ($this->max - $this->min) * 100
, 3
); } else {
$newRange = round($this->min * 100
, 3
); }
$strLabels = '0:';
$strPosition = '0';
for ($a = $this->getFirstOfRange($rangeY); $a <= $this->max; $a += $rangeY) {
$strLabels .= '|' . $a;
}
for ($a = $this->getFirstGrid($rangeY); $a <= 100; $a += $newRange) {
$strPosition .= ',' . $a;
}
$this->_axis = 'y,x';
$this->_axisRange = $strLabels . '|1:|' . $labelsX;
$this->_axisPosition = $strPosition;
}
public function setGrids ($rangeY) {
if ($this->max != $this->min) {
$newRangeY = round($rangeY / ($this->max - $this->min) * 100
, 3
); $newRangeX = round(100
/ (count($this->baseData) - 1
), 2
); } else {
$newRangeY = round($rangeY / $this->min * 100
, 3
); $newRangeX = round(100
/ (count($this->baseData) - 1
), 2
); }
$this->_grids = $newRangeX . ',' . $newRangeY . ',3,3,0,' . $this->getFirstGrid($rangeY);
}
private function getFirstGrid($rangeY) {
if ($this->max != $this->min) {
return round((1
- ($this->max - $this->getFirstOfRange($rangeY)) / ($this->max - $this->min)) * 100
, 3
); } else {
return round((1
- ($this->max - $this->getFirstOfRange($rangeY)) / $this->min) * 100
, 3
); }
}
private function getFirstOfRange($rangeY){
for ($pierwszyPodzielny = $this->min; $pierwszyPodzielny <= $this->max; $pierwszyPodzielny++){
if (abs($pierwszyPodzielny) % $rangeY == 0
|| $pierwszyPodzielny == 0
) break;
}
return $pierwszyPodzielny;
}
}
?>
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