Laravel ChartJs how to get the array from the object?

Not long ago began to study the framework question :
in the controller create a variable that displays information by months:
[{"month":"July","monthNum":"2018-07","devices":14},{"month":"August","monthNum":"2018-08","devices":2}]

The question - how to transfer data from the variable $device {"month":"July"}, 'labels'=> ['month'] and $device {"devices":14} in dataset['data' =>[devices]]?
June 3rd 19 at 19:31
1 answer
June 3rd 19 at 19:33
Apply via AJAX to the controller. The controller will return json and then on the client parse the received json.
$.ajax({
 method: 'POST',
 url: 'url',
 success: function (data) {
 var month=[];
 var device=[];

 $.each(JSON.parse(data), function(index, report)
{
month.push(report.month)
});
 $.each(JSON.parse(data), function(index, name)
{
device.push(name.devices)
});

 //Build chart
 var ctx = document.getElementById('chart').getContext('2d');
 regionChart = new Chart(ctx, {
 // The type of chart we want to create
 type: 'horizontalBar',
dataType:'json',
 // The data for our dataset
 data: {
 labels: month,
 datasets: [{
 label: "Chart",
 data: device,
}]
 }, 
});
}
 });
Thank you, in the future will be useful, but at the moment I had a plan to implement all in the controller, now it worked, made on the knee, while records in the database a little, not scared, then the mind will be typed correct :)
foreach ($objects as $key => $value) {
foreach ($value as $key1 => $value1) {
// code...
if($key1=='month') $objects1[]=$value1;
if($key1=='devices') $objects2[]=$value1;
}
}

linechart:
import { Line, mixins } from 'vue-chartjs'

export default {
extends: Line,
mixins: [mixins.reactiveProp],
props: ['chartData', 'options'],
mounted () {
this.renderChart(this.chartData, this.options)
}
}

dashboard:

- nikita.Stracke commented on June 3rd 19 at 19:36

Find more questions by tags JavaScript