Google charts returns graphics before display div

0

I have a problem when making an ajax call like the following one. The graphic function (code) draws me a Google charts graphic. The problem is that the div id="chart" is in the response html of the ajax call. If the call of the graph is made before, it indicates that it is null div id="chart" and does not return the graph. Best way to fix it?

I tried to call the graphic function (code) after showing the container but I still have the problem ....

$.ajax({                    
                url:"buscar_info.php",
                type:"POST",
                data:codigo,
                dataType:"html",
                success:
                    function(respuesta)
                            {     
                            grafico(codigo);
                            $("#contenedor").show('fast');
                            $("#contenedor").html(respuesta);
                            }
                    });

Thanks. Greetings

    
asked by user3220425 10.10.2017 в 09:55
source

1 answer

0

Nothing forgives .. I could access now with mozilla mark me this error the firebug:

TypeError: google.visualization.Datatable is not a constructor

I put the code of the graphic function

google.charts.load('current', {'packages':['corechart','line']});

function grafico(codigo){
        var codigo=codigo;
         $.ajax({
            url:"buscar_json.php",
            type:"POST",  
            data:codigo_tienda,
            dataType:"json",                  
            success:
            function(resultado){
            
             
                  $("#container_grafico_ventas").show();
                
      var dataVentas=resultado.ventas;
        var dataVentas = new google.visualization.DataTable();
                      dataVentas.addColumn('string', 'Mes');
                      dataVentas.addColumn('number', '2016');
                      dataVentas.addColumn('number', '2017');
     
        dataVentas.addRows([dataSetVentas[0],dataSetVentas[1]]);
  
              var options = {
                    isStacked: 'true',
                      'width':dWidth,
                    'height':400,
                    series: {
                      0: { color: '#E3141C' },   
                      1: { color: '#ff00d4' },
                  }
                 
        };


        var chartVentas = new google.visualization.LineChart(document.getElementById('grafico_ventas'));
         
        chartVentas.draw(dataVentas, options);
    
answered by 10.10.2017 в 10:46