Morris charts & PHP issues
<p>I'm struggling with Morris charts for some time now. I'm trying to call data from Mysql table using PHP code but keep getting this error.</p>

<pre><code>Uncaught TypeError: Cannot read property 'length' of undefined
</code></pre>

<p>But when I inspect site I see that I got json so I believe that encoding was successful</p>

<pre><code>    Morris.Bar({
    element: 'brojLampi',
    data: [{"label":"Mali Tabor","value":"5"},{"label":"Prišlin","value":"24"}]*//output*,
    xkey: 'naziv_naselja',
    ykey: 'broj',
    labels:['naziv_naselja'],
    });
</code></pre>

<p>Here is PHP code:</p>

<pre><code>&lt;div id="morris-area-chart"&gt;&lt;/div&gt;
&lt;?php
try {
    $db  = connectPDO();
    $row = $db-&gt;prepare("SELECT naziv_naselja, count(naziv_naselja) AS broj FROM v_rasvjeta GROUP BY naziv_naselja");
    $row-&gt;execute();

    $json_data = array(); 
    foreach ($row as $rec) { 
        $json_array['label'] = $rec['naziv_naselja'];
        $json_array['value'] = $rec['broj'];
        array_push($json_data, $json_array);

    }
?&gt;
    &lt;div id="brojLampi"&gt;&lt;/div&gt;
    &lt;script type="application/javascript"&gt;
    Morris.Bar({
    element: 'brojLampi',
    data: &lt;?php
    echo json_encode($json_data, JSON_UNESCAPED_UNICODE);
?&gt;,
    xkey: 'label',
    ykey: 'value',
    labels:['Name']
    });

    &lt;/script&gt;
    &lt;?php
    closePDO($db);
} 
catch (PDOException $e) {
    showPDOErrors($e, $db);
}
?&gt;
</code></pre>

<p>Even, I tried something like this but it didn't work</p>

<pre><code>$.getJSON("brojLampi", function (data) {    
Morris.Bar({
element: 'brojLampi',
data: &lt;?php echo json_encode($json_data,JSON_UNESCAPED_UNICODE)?&gt;,
xkey: 'naziv_naselja',
ykey: 'broj',
labels:['naziv_naselja'],
});
});
</code></pre>

<p>I got this error when using code above:</p>

<pre><code>GET http://localhost:8081/APLIKACIJE/RASVJETA/stranice/brojLampi 404 (Not Found)
</code></pre>

<p>Any help would be appreciative :) </p>