concerning function _chart_adjust_resolution($chart_id, &$data, $max_value = NULL)

if $max[$chart_id] is 0, a division by zero error is thrown

attached patch solves this by changing this

    if ($max[$chart_id] > $resoluton){
      $divider = round($max[$chart_id] / $resoluton, 1);
    }
    else {
      $multiplier = round($resoluton / $max[$chart_id], 1);
    }

into this

    if ($max[$chart_id] > $resoluton){
      $divider = round($max[$chart_id] / $resoluton, 1);
    }
    elseif ($max[$chart_id] != 0) {
      $multiplier = round($resoluton / $max[$chart_id], 1);
    }

should apply to HEAD

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

seutje’s picture

By the way, I got this error in combination with the google analytics API module, not sure if this is chart API's fault for not catching it, or google analytics API's fault for calling a function with improper values

-> #551146: Division by zero error when viewing a report and bounce rate is zero

alberto56’s picture

from what I can tell, It's a chart problem because it's logically valid to have zero as a max value.

The patch works for me, thanks. However I'll leave it at "needs review" because I'm not entirely sure how this function works, especially with negative ranges, ranges from negative to zero, and other case.

mstef’s picture

I did:

$max[$chart_id] = max($max[$chart_id], 1);
$multiplier = round($resoluton / $max[$chart_id], 1);  
Fleshgrinder’s picture

It should be:

    if ($max[$chart_id] > $resoluton){
      $divider = round($max[$chart_id] / $resoluton, 1);
    }
    elseif ($max[$chart_id] > 0) {
      $multiplier = round($resoluton / $max[$chart_id], 1);
    }

Because negative values will also produce errors.

mstef’s picture

Attaching my patch

mstef’s picture

Surprised to see 1.3 release not including this

ManyNancy’s picture

Priority: Normal » Major

Changes to major as the error message is ugly.

mstef’s picture

Patch for the new 1.3 release

aaron1234nz’s picture

Status: Needs review » Reviewed & tested by the community

Patch in #8 applies (with a slight fuzz) and fixes the problem.

craigmc’s picture

Yup. tested, works. plz include in module.

ximo’s picture

FileSize
419 bytes

Here's a hotfix patch for 7.x-1.0, in case anyone's in need of that. I did the same as Fleshgrinder in #4.

13rac1’s picture

@ximo: Git reports "fatal: git diff header lacks filename information when removing 1 leading pathname components (line 5)" for your patch. I manually applied the change.

This fix has been committed to 7.x-1.x-dev. May be changed again when #234127: Negative Data values? and #1213796: _chart_adjust_resolution calculation are resolved.

13rac1’s picture

Status: Reviewed & tested by the community » Fixed

Applied to change in #11 to 6.x-1.x.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Juan David’s picture

Thanks for the tip, it really works and make the warning go away.

sorry for my english.

Thanks again.

Pierre.Vriens’s picture

Issue summary: View changes
Parent issue: » #2371567: Chart 6.x-2.x Release