JSON Parse Error

I get the following error message when im loading Visitors > Overview > Report > Actions but ONLY in the weeks view!

Open Flash Chart

JSON Parse Error [Bad Object]
Error at character 10209, line 255:

252:     "grid-colour": "#E0E1E4",253:     "min": 0,254:     "max": 2.0e+5,

This is a bug in Open Flash Charts 2 because “2.0e+5” is a valid numeric format in JSON. I’ve reported it upstream…

At the moment, I don’t have a workaround. AFAIK, Piwik and the OFC library aren’t converting it to e-notation, so this might be occurring in a php built-in function, e.g., json_encode().

I wonder if somewhere the int is being converted to float because there’s some oddness in PHP when it comes to floats. Try the code from: http://www.php.net/manual/en/language.types.float.php#83577

Do you get 200000 or 2.0e+5?

In core/Visualization/Chart.php, in the getMaxValue() function, try changing:

Index: Chart.php
===================================================================
--- Chart.php    (revision 1258)
+++ Chart.php    (working copy)
@@ -107,7 +107,7 @@
         {
             $maxCrossDataSets = $maxCrossDataSets + 10 - $maxCrossDataSets % 10;
         }
-        return $maxCrossDataSets;
+        return (int) $maxCrossDataSets;
     }
     
     public function setTitle($text, $css)

Please also state what version of PHP and operating system you’re using.

I tried the code from: http://www.php.net/manual/en/language.types.float.php#83577 and got int 200000

OS: openSUSE 10.2 (2.6.18.2-34-xen)
PHP 5.2.0

With the change in the Chart.php I get the error message in another line:

Open Flash Chart

JSON Parse Error [Bad Object]
Error at character 10231, line 256:

253:     "min": 0,254:     "max": 200000,255:     "steps": 1.0e+5,

Ok. Make this additional change to Chart.php:

@@ -161,7 +161,7 @@
         $this->y->set_colour('#ffffff');
         $this->y->set_grid_colour($gridColour);
         $stepsCount = 2;
-        $stepsEveryNLabel = ceil(($this->maxValue - $this->minValue) / $stepsCount);
+        $stepsEveryNLabel = (int) ceil(($this->maxValue - $this->minValue) / $stepsCount);
         if($this->maxValue == 0)
         {
             $this->maxValue = 1;

Let us know if this works for you, so I can commit it to svn.

Yes, that works! style_emoticons/<#EMO_DIR#>/smile.gif Thank you.

Thanks.

In hindsight, I’ll be changing the patch, moving the casts to where we call setRange()/set_range() [?] but the desired effect should be the same.

i’m experiencing the same kind of error but the patches don’t seem to fix it:

Open Flash Chart

JSON Parse Error [Bad Object]
Error at character 182, line 9:

6: "type": "hollow-dot",7: "value": 0,8: "tip": "Thu 4 Jun<br>0 Conversions (goal \\"test\\")",

That’s because it’s a different problem. Are you running 0.4.1?

yep, piwik 0.4.1
centos 5, php 5.1.6

Here’s the fix to libs/upgradephp/upgrade.php:

Index: upgrade.php
===================================================================
--- upgrade.php    (revision 1270)
+++ upgrade.php    (working copy)
@@ -140,7 +140,7 @@
          if (!utf8_decode($var)) {
             $var = utf8_encode($var);
          }
-         $var = str_replace(array("\"", "\\", "/", "\b", "\f", "\n", "\r", "\t"), array("\\\"", "\\\\", "\\/", "\\b", "\\f", "\\n", "\\r", "\\t"), $var);
+         $var = str_replace(array("\\", "\"", "/", "\b", "\f", "\n", "\r", "\t"), array("\\\\", "\\\"", "\\/", "\\b", "\\f", "\\n", "\\r", "\\t"), $var);
          $json = '"' . $var . '"';
          //@COMPAT: for fully-fully-compliance   $var = preg_replace("/[\000-\037]/", "", $var);
       }

style_emoticons/<#EMO_DIR#>/smile.gif

that did the trick,
thx!