I'm getting: Data column (s) for axis # 0 can not be of type string

0

I have a small function that is responsible for obtaining a series of data:

AngularJS

$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();

Data returned by the query (In production):

Data returned by the Array (Local):

But I get a result in the view:

How can I or what is being omitted to generate the aforementioned error?

    
asked by jecorrales 27.01.2018 в 17:53
source

1 answer

1

You have to specify the date format that the value will be parsed:

var options =
        {
          title: 'Gráfica de Visitantes',
          hAxis: {title: 'Fecha', titleTextStyle: {color: 'Black'}, format: "yyyy-MM-dd"},
          vAxis: {minValue: 0}
        };

And you should also delete the first result of the array since it is returning the names of the columns and that is a value that can not be converted to date:

//...

.then(function successCallback(datosEstadisicasMeses) {

    // verificamos que tenga datos
    if(datosEstadisicasMeses.length>0)
    {
            // eliminamos el primer registro
            datosEstadisicasMeses.splice(0,1);
    }

    //...
    
answered by 02.02.2018 / 16:46
source