Uncaught (in promise) Error: Row 1 has 42 columns, but must have 2
Uncaught (in promise) Error: Row 1 has 42 columns, but must have 2
I'm using google bar charts for my project and I create an ajax function to load charts with data. But when I use jquery each function to create data bars in google charts its getting error called
Uncaught (in promise) Error: Row 1 has 42 columns, but must have 2
. Can Anyone show me the error in my code
这是我的图表代码
//chart 2
google.charts.load('current', {
'packages': ['bar']
});
google.charts.setOnLoadCallback(drawChart1);
function drawChart1() {
var dataa1 = google.visualization.arrayToDataTable([
['DS Division', 'No of Youths'],
$.each(data.locations, function(index, value3) {
['' + value3.DSD_Name + '', value3.total]
}),
]);
var options1 = {
chart: {
},
bars: 'horizontal', // Required for Material Bar Charts.
legend: {
position: 'none'
},
};
var chart1 = new google.charts.Bar(document.getElementById('barchart_material'));
chart1.draw(dataa1, google.charts.Bar.convertOptions(options1));
}
这是我来自控制器的响应数据
return response() => json(array(
'male' => $male,
'female' => $female,
'locations' => $locations,
'salary1' => $salary1,
'salary2' => $salary2,
'salary3' => $salary3,
'salary4' => $salary4,
'salary5' => $salary5,
'salary6' => $salary6,
'employers' => $employers
));
请帮我解决这个问题
谢谢
而不是尝试在数组声明中循环,
使用循环将值添加到数组...
var chartData = [
['DS Division', 'No of Youths'],
];
$.each(data.locations, function(index, value3) {
chartData.push([value3.DSD_Name, value3.total]);
});
var dataa1 = google.visualization.arrayToDataTable(chartData);
I'm using google bar charts for my project and I create an ajax function to load charts with data. But when I use jquery each function to create data bars in google charts its getting error called
Uncaught (in promise) Error: Row 1 has 42 columns, but must have 2
. Can Anyone show me the error in my code
这是我的图表代码
//chart 2
google.charts.load('current', {
'packages': ['bar']
});
google.charts.setOnLoadCallback(drawChart1);
function drawChart1() {
var dataa1 = google.visualization.arrayToDataTable([
['DS Division', 'No of Youths'],
$.each(data.locations, function(index, value3) {
['' + value3.DSD_Name + '', value3.total]
}),
]);
var options1 = {
chart: {
},
bars: 'horizontal', // Required for Material Bar Charts.
legend: {
position: 'none'
},
};
var chart1 = new google.charts.Bar(document.getElementById('barchart_material'));
chart1.draw(dataa1, google.charts.Bar.convertOptions(options1));
}
这是我来自控制器的响应数据
return response() => json(array(
'male' => $male,
'female' => $female,
'locations' => $locations,
'salary1' => $salary1,
'salary2' => $salary2,
'salary3' => $salary3,
'salary4' => $salary4,
'salary5' => $salary5,
'salary6' => $salary6,
'employers' => $employers
));
请帮我解决这个问题
谢谢
而不是尝试在数组声明中循环,
使用循环将值添加到数组...
var chartData = [
['DS Division', 'No of Youths'],
];
$.each(data.locations, function(index, value3) {
chartData.push([value3.DSD_Name, value3.total]);
});
var dataa1 = google.visualization.arrayToDataTable(chartData);