title: how to properly format data for morris js
body: <p>I am using morris js for creating chart in my application. And I have a response from backend like below</p>
  <pre><code>{ duration: '', income: 0, expense:0 },
  </code></pre>
  <p>bur as morris js needs array so that i am try to assign in an array like below</p>
  <pre><code>results = [response.income_expense];
  </code></pre>
  <p>and after assigning when I console log this value I got below output</p>
  <pre><code> console.log(results);
      [&quot;{ duration: '', income: 0, expense:0 },&quot;]
  0: &quot;{ duration: '', income: 0, expense:0 },&quot;
  </code></pre>
  <p><strong>but I want an output like below</strong></p>
  <pre><code>(4) [{…}, {…}, {…}, {…}]
  0: {duration: &quot;2021&quot;, income: 537000, expense: 337000}
  1: {duration: &quot;2020&quot;, income: 368500, expense: 568500}
  2: {duration: &quot;2019&quot;, income: 268500, expense: 168500}
  3: {duration: &quot;2018&quot;, income: 368500, expense: 568500}
  </code></pre>
  <p>please help me to get the desired output</p>
  <p>addittionally i have this functions in backend</p>
  <pre><code>public function dashboardData(Request $request)
      {
          try {
              $data = $this-&gt;widgets($request-&gt;type);
              $data['income_expense'] = $this-&gt;incomeExpense($request-&gt;type);
  
              return $data;
          } catch (\Exception $e) {
              LogActivity::errorLog($e-&gt;getMessage());
              return response()-&gt;json([
                  'error' =&gt; trans('common.Something Went Wrong')
              ]);
          }
      }
  </code></pre>
  <p>and this one is my trait</p>
  <pre><code>public function incomeExpense($type): string
      {
          $chart_data_yearly = '';
          $income_expense = $this-&gt;transactionRepo-&gt;incomeExpense($type);
  //        dd($income_expense);
  
          foreach ($income_expense as $k =&gt; $row) {
              $income = $this-&gt;transactionRepo-&gt;incomeByDate($row-&gt;transaction_date, $type);
              $expense = $this-&gt;transactionRepo-&gt;expenseByDate($row-&gt;transaction_date, $type);
  
              $chart_data_yearly .= &quot;{ duration: '&quot; . $row-&gt;duration . &quot;', income: &quot; . $income . &quot;, expense:&quot; . $expense . &quot; },&quot;;
          }
  
          return $chart_data_yearly;
      }
  </code></pre>