I have a small concern, I currently need to generate statistics of records by dates of the year:
MYSQL CONSULTATION
SELECT fecha_registro AS Fecha,
count(*) AS Registros
FROM persona
WHERE id_tipoUsuario = '4'
AND empresa_per = '$id_empresa'
GROUP BY MONTH(Fecha)
RESULT
The query responds to what was expected, which is to obtain the records made during the corresponding month.
RESULTS CONSULTATION
ANGULAR FUNCTION
$scope.importarEstadisticas = function()
{
$http({
method: 'GET',
url: 'mainApp/Estadisticas/estadisticaMeses.php'
})
.then(function successCallback(datosEstadisicasMeses)
{
$scope.tableEstadisticas = datosEstadisicasMeses.data;
},function errorCallback(datosEstadisicasMeses)
{
console.log("Error, al tratar de traer los datos")
});
}
$scope.importarEstadisticas();
RESULT FUNCTION
GOOGLE CHART
//FUNCION QUE SE ENCARGA DE LLAMAR LOS METODOS PARA OBTENER DATOS DE NOTIFICACIONES
$scope.importarEstadisticas = function()
{
$http({
method: 'GET',
url: 'mainApp/Estadisticas/estadisticaMeses.php'
})
.then(function successCallback(datosEstadisicasMeses)
{
$scope.tableEstadisticas = datosEstadisicasMeses.data;
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart()
{
var cabeceras = Object.keys($scope.tableEstadisticas[0]); //Aqui se obtiene los valores Fecha y Registros, para las cabeceras de tu grafico.
var formatoGrafico = [];
formatoGrafico.push(cabeceras); //Se dejan como primer elemento en el arreglo Formato.
$scope.tableEstadisticas.forEach(function(registro, index) {
//Se recorren los datos y se cargan al arreglo con el mismo formato.
formatoGrafico.push([registro.Fecha, registro.Registros]);
});
var data = google.visualization.arrayToDataTable([formatoGrafico]);
var options =
{
title: 'Gráfica de Visitantes',
hAxis: {title: 'Fecha', titleTextStyle: {color: 'Black'}},
vAxis: {minValue: 0}
};
var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
},function errorCallback(datosEstadisicasMeses)
{
console.log("Error, al tratar de traer los datos")
});
}
$scope.importarEstadisticas();
This is where my problem lies, because I need to pass the data obtained from my query to the GoogleChart array. Derived in its two rows, Date and Records. Instead of Month it would be the date obtained, and instead of the values given manually it would be the count obtained from the consuolta.
Thank you!