title: How to make morris donut chart with ajax json?
body: <p>How to make morris donut chart with ajax json ?</p>
  
  <p>this is my code :</p>
  
  <pre><code>$(function() {
  
  $.ajax({
      url : 'dashboard/total-data',    
  }).done(function(data){
      initDonut(JSON.parse(data));
      console.log(data);
  }).fail(function(){
  
  });
  
  var initDonut = function(data){
  
      return Morris.Donut({
          element: 'morris-donut-chart',
          data: [ data ],
          // data: [ 
                  // {label: "BMW", value: 4},
                  // {label: "Mercy", value: 0},
                  // {label: "Ferrari", value: 0},
                  // {label: "Toyota", value: 3},
                  // {label: "Porsche", value: 0},
                  // {label: "Limosin", value: 0},
                  // {label: "Lamborgini", value: 3} ],
          resize: true,
          colors: ['#87d6c6', '#54cdb4','#1ab394', '#54cdb4','#1ab394', '#54cdb4','#1ab394'],
      });
  
  } });
  </code></pre>
  
  <p>Ajax code above return data format like this:</p>
  
  <pre><code>{"BMW":4,"Mercy":0,"Ferrari":0,"Toyota":3,"Porsche":0,"Limosin":0,"Lamborgini":3}
  </code></pre>
  
  <p>my question, </p>
  
  <p>How to make format data above become like this with javascript?</p>
  
  <pre><code>[ {label: "BMW", value: 4},{label: "Mercy", value: 0},{label: "Ferrari", value: 0},{label: "Toyota", value: 3},{label: "Porsche", value: 0},{label: "Limosin", value: 0},{label: "Lamborgini", value: 3} ]
  </code></pre>
  
  <p>This is code for show json:</p>
  
  <pre><code>public function total_data()
  {
      $data['BMW']        = $this-&gt;m_dashboard-&gt;get_total_product_bmw();
      $data['Mercy']      = $this-&gt;m_dashboard-&gt;get_total_product_mercy();
      echo json_encode($data);
      $data['Ferrari']    = $this-&gt;m_dashboard-&gt;get_total_product_ferrari();
      $data['Toyota']     = $this-&gt;m_dashboard-&gt;get_total_product_toyota();
      $data['Porsche']    = $this-&gt;m_dashboard-&gt;get_total_product_porsche();
      $data['Limosin']    = $this-&gt;m_dashboard-&gt;get_total_product_limosin();
      $data['Lamborgini'] = $this-&gt;m_dashboard-&gt;get_total_product_lamborgini();
      echo json_encode($data);
  }
  </code></pre>