title: How to send my MySQL data with PHP code to morris-data.js?
body: <p>I got a problem how to make morris chart with data from MySQL database. I have made a php code with output like how JSON template can accepted to morris-data.js.</p>
  
  <p>Here's my php code name cobaJson.php:</p>
  
  <pre><code>&lt;link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css"&gt;
  &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"&gt;&lt;/script&gt;
  &lt;script src="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js"&gt;&lt;/script&gt;
  
  &lt;?php
  include_once("koneksi.php");
  
  $query = "SELECT * FROM data_graph ORDER BY x ASC";
  $result = mysql_query( $query );
  
  while ( $row = mysql_fetch_assoc( $result ) ) 
  {  
      $prefix = '';
      echo "[&lt;br /&gt;";
      while ( $row = mysql_fetch_assoc( $result ) ) 
      {
          echo $prefix . " {&lt;br /&gt;";
          echo '  x: ' . $row['x'] . ',' . "&lt;br /&gt;";
          echo '  y: ' . $row['y'] . ',' . "&lt;br /&gt;";
          echo '  z: ' . $row['z'] . ',' . "&lt;br /&gt;";
          echo '  a: ' . $row['a'] . '' . "&lt;br /&gt;";
          echo " }";
          $prefix = ",&lt;br /&gt;";
      }
      echo "&lt;br /&gt;]";
  }
  ?&gt;
  </code></pre>
  
  <p>And here's the output :</p>
  
  <blockquote>
    <p>[ { x: 2012, y: 11, z: 6, a: 9 }, { x: 2014, y: 3, z: 3, a: 1 }, { x:
    2015, y: 4, z: 7, a: 9 } ]</p>
  </blockquote>
  
  <p>And I try to send this php code to my morris-data.js :</p>
  
  <pre><code>    $(function() {
  var json = (function () {
          var json = null;
          $.ajax({
              'async': false,
              'global': false,
              'url': 'cobaJson.php',
              'dataType': "json",
              'success': function (data) {
                  json = data;
              }
          });
          return json;
      })
      ();
  
  
      Morris.Bar({
          element: 'morris-bar-chart',
          data: json,
          xkey: 'x',
          ykeys: ['y', 'z', 'a'],
          labels: ['Series A', 'Series B', 'Series B'],
          hideHover: 'auto',
          resize: true
      });
  
  });
  </code></pre>
  
  <p>But it still not work, anyone can you help me?</p>