My goal is to obtain a graph from an array obtained by JQuery
I import the Google Chart
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
The block where I get that array is the following:
$.get("Inform.php?proyecto="+$("#Proyectos option:selected").text(), function( data ){
$.each(data, function(id,value){
var tmp = {
'value1':""+value['value1']+"",
'value2':""+value['value2']+"",
'solution':""+value['solution']+""
};
ListaA.push(tmp);
});
});
google.load('visualization', '1', {'packages': ['corechart']});
google.setOnLoadCallback(drawChart);
return;
Now the drawChart () function
function drawChart(){
try{
var dataTable = new google.visualization.DataTable(listaA);
var options = {
'title':'Title',
'width':400,
'height':300
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(dataTable, options);
}catch(err){
alert(err.message);
}
}
Finally the div where I want my graph to be loaded
<div id="piechart" style="width: 900px; height: 500px;"></div>
As you will have seen in the third block of code, I used try / catch to verify if I get errors and know what type it can be, but when running the code nothing happens, neither loads the graph nor I get an error. I tried to load the resulting array into a table and it shows me the expected results, so the problem is not a null array, maybe I'm missing a step or I did it wrong when using the Google Chart library.
I am attentive to your advice and suggestions on my case. Thank you very much for your attention and time.