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:

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.
 method: 'POST',
 url: 'url',
 success: function (data) {
 var month=[];
 var device=[];

 $.each(JSON.parse(data), function(index, report)
 $.each(JSON.parse(data), function(index, name)

 //Build chart
 var ctx = document.getElementById('chart').getContext('2d');
 regionChart = new Chart(ctx, {
 // The type of chart we want to create
 type: 'horizontalBar',
 // 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;

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

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


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

Find more questions by tags JavaScript