it´s a simple question but i can´t solve. Always when i tray to do loopp in my array return index 0
<script>
let status = [];
let number = [];
let llamadas = [];
llamadas = {!! json_encode($estados) !!}
for(var i=0; i<llamadas.length; i++){
console.log(llamadas[i][i]);
status.push(llamadas[i][i].desc);
number.push(llamadas[i][i].total)
}
llamadas its my varaible from controller, i´m working with laravel 5.6 how backend
llamadas contain this:
(7) [{…}, {…}, {…}, {…}, {…}, {…}, {…}]
0: {id_teleoperadora: 9, desc: "APLAZADA", total: 40}
1: {id_teleoperadora: 9, desc: "AUSENTE", total: 132}
2: {id_teleoperadora: 9, desc: "CONFIRMADA", total: 218}
3: {id_teleoperadora: 9, desc: "NUEVA", total: 101}
4: {id_teleoperadora: 9, desc: "NULA", total: 217}
5: {id_teleoperadora: 9, desc: "PENDIENTE", total: 45}
6: {id_teleoperadora: 9, desc: "VENTA", total: 1}
length: 7
__proto__: Array(0)
and his original content content wihtout for
[Array(7)]
0: (7) [{…}, {…}, {…}, {…}, {…}, {…}, {…}]
length: 1
__proto__: Array(0)
never i show one array for this way
in push i need extract desc for to build to stadictics with chart.js. now i can return only one state. I don´t know that i´m doing wrong. when i have status i will continue with number but now only i can return one result status "aplazada" i don´t know if i´m doing well my pushs
thanks for help
Advertisement
Answer
In my controller i has error, should be:
public function getStateCallCommercial($operadora)
{
$callSend = array();
array_push($callSend, DB::select(
DB::raw("SELECT L.id_teleoperadora, CE.desc, COUNT(C.id) as total
FROM LLAMADA L
JOIN CITA C ON L.ID = C.id_llamada
JOIN CITA_ESTADO CE ON C.id_estado = CE.id
WHERE L.id_teleoperadora = $operadora
AND L.id_estado = 5
GROUP BY L.id_teleoperadora, CE.desc
ORDER BY CE.desc;" ) )
);
return view('admin.estadisticas.index')->with('estados', $callSend[0]);
this send my data to view. and in my blade:
<script>
let status = [];
let number = [];
let llamadas = [];
llamadas = {!! json_encode($estados) !!};
for(var i=0; i<llamadas.length; i++){
status.push(llamadas[i].desc);
number.push(llamadas[i].total)
}
var ctx = document.getElementById('myChart').getContext('2d');
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: status,
datasets: [{
label: 'Estado de las llamadas pasadas a comerciales',
data: number,
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
with this i build my graphic.
Thanks for all response and help