jQuery load Google Visualization API with AJAX

后端 未结 10 2265
栀梦
栀梦 2020-12-24 02:17

There is an issue that I cannot solve, I\'ve been looking a lot in the internet but found nothing.

I have this JavaScript that is used to do an Ajax request by PHP.

10条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-24 03:13

    This works for me

    google.load("visualization", "1", { packages: ["corechart"] });
    
                 var chart ;
                 var data ;
                 var options;
            function Change(s)
            {
                  // s in json format    
                  google.setOnLoadCallback(reDraw(s));
                  function reDraw(s) {
                      console.log(new Function("return " + s)().length); // to test if json is right
                      data = google.visualization.arrayToDataTable(new Function("return "+s)());
    
                        options = {
                        title: 'Product Scanes',
                        vAxis: { title: '', titleTextStyle: { color: 'red'} }         
                    };
    
                  }         
                    chart = new google.visualization.BarChart(document.getElementById('chart_div'));
                    chart.draw(data, options);
            }  
            function requestDate() // cal the method when you want to draw the chart 
            {
    
                $.ajax({
                    type: "POST", // CHANGED
                   // contentType: "application/json; charset=utf-8",
                    url: "something.php",
                    data: {  parameters you wanna pass },
                    success: function (d) { 
                    Change(d);
    
    
                    }
                });    
            }
    }
    

提交回复
热议问题