title: How to show only last 3 months in morris chart in laravel
body: <p>I have been facing a problem in my project. I want to how last 3 months activity in my morris chart. But don't know how to achieve this.</p>
  
  <p>Here is what I got:</p>
  
  <p><a href="https://i.stack.imgur.com/IU14t.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IU14t.png" alt="enter image description here"></a></p>
  
  <p>In this I got August multiple times. What I want is only 3 months: August, September, October. </p>
  
  <p>Here is what I tried:</p>
  
  <pre><code>public function sales() {
      $company = Auth::guard('company')-&gt;user()-&gt;id;
      $date = Carbon::now();
      $currentmonth = Order::where([['company_id', $company], ['status', '&lt;&gt;', 0]])-&gt;whereDate('created_at', '&gt;=', $date-&gt;copy()-&gt;startOfMonth())-&gt;whereDate('created_at', '&lt;=', $date-&gt;copy()-&gt;endOfMonth())-&gt;get();
      $lastmonth = Order::where([['company_id', $company], ['status', '&lt;&gt;', 0]])-&gt;whereDate('created_at', '&gt;=', $date-&gt;copy()-&gt;startOfMonth()-&gt;subMonth())-&gt;whereDate('created_at', '&lt;=', $date-&gt;copy()-&gt;endOfMonth()-&gt;subMonth())-&gt;get();
      $anothermonth = Order::where([['company_id', $company], ['status', '&lt;&gt;', 0]])-&gt;whereDate('created_at', '&gt;=', $date-&gt;copy()-&gt;startOfMonth()-&gt;subMonths(2))-&gt;whereDate('created_at', '&lt;=', $date-&gt;copy()-&gt;endOfMonth()-&gt;subMonths(2))-&gt;get();
  
      $data = [
          [ 'year'=&gt; $date-&gt;year . '-' . $date-&gt;copy()-&gt;startOfMonth()-&gt;subMonths(2)-&gt;format('m'), 'value'=&gt; $anothermonth-&gt;sum('price') ],
          [ 'year'=&gt; $date-&gt;year . '-' . $date-&gt;copy()-&gt;startOfMonth()-&gt;subMonth()-&gt;format('m'), 'value'=&gt; $lastmonth-&gt;sum('price') ],
          [ 'year'=&gt; $date-&gt;year . '-' . $date-&gt;copy()-&gt;format('m'), 'value'=&gt; $currentmonth-&gt;sum('price') ],
      ];
  
      $json = json_encode($data);
  
      return view('company.dashboard.sales', compact('json'));
  }
  </code></pre>
  
  <p>And my JavaScript is:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  var months = ["JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"];
  
  var area = new Morris.Area({
      element: 'revenue-chart',
      resize: true,
      data: {!! $json !!},
      xkey: 'year',
      ykeys: ['value'],
      lineColors: ['#75a5c1'],
      hideHover: 'auto',
      xLabelFormat: function(x) { // &lt;--- x.getMonth() returns valid index
          var month = months[x.getMonth()];
          return month;
        },
        dateFormat: function(x) {
          var month = months[new Date(x).getMonth()];
          return month;
      },
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>Please help me.</p>