title: Php Array to line chart in ChartJs
body: <pre><code>        $days = ["Monday","Tuesday","Wednesday"];
          $rates = [40,60,80];
          $profit = [];
  
          foreach($days as $day =&gt; $value){
              foreach($rates as $rate){
                  $netprofit = $rate* 20;
                  $profit[$value] = [$rate=&gt; $netprofit];
              }
  
          }
  </code></pre>
  
  <pre><code>        $usersChart = new UserChart;
          $usersChart-&gt;labels($days);
          foreach($profit as $key =&gt; $value){
              $data = array();
              foreach ($value as $values){
                  $data[] = $values;
              }
  
  
              $usersChart-&gt;dataset($key, 'line', collect($data));
          }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Cy9X3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Cy9X3.png" alt="Chart generated by the above code."></a>
  I want to show this array into Chartjs Line Graph. I want the x axis to be the 40,60,80. Y axis to be 800, 1200, 1600. The Dataset or Lines should be Monday, Tuesday and Wednesday.
  Right now i get Monday, Tuesday and Wednesday as x axis and Line. 600,800 etc are on y axis.</p>
  
  <pre><code>Array
  (
      [Monday] =&gt; Array
          (
              [40] =&gt; 800
              [60] =&gt; 1200
              [80] =&gt; 1600
          )
  
      [Tuesday] =&gt; Array
          (
              [40] =&gt; 800
              [60] =&gt; 1200
              [80] =&gt; 1600
          )
  
      [Wednesday] =&gt; Array
          (
              [40] =&gt; 800
              [60] =&gt; 1200
              [80] =&gt; 1600
          )
  
  )
  </code></pre>