/ / Remplir Google Charts avec une variable ajax xml - javascript, jquery, ajax, google-visualization

Remplir Google Charts avec une variable ajax xml - javascript, jquery, ajax, google-visualization

Comment pourrais-je obtenir ma variable "totale" dans ma fonction xmlParser à afficher en tant que variable pour Google Charts.

Violon

Réponses:

1 pour la réponse № 1

Vous devez déplacer l'appel AJAX dans la fonction drawChart et renseigner les données à partir de celui-ci. Voici une façon de le faire:

function drawChart() {
$.ajax({
type: "GET",
dataType: "xml",
async: true,
url: "https://test/computers",
contentType: "text/xml; charset=utf-8",
success: function  (xml) {
var size = $(xml).find("size");
var total = (size.text());

var data = google.visualization.arrayToDataTable([
["Task", "Hours per Day"],
["Work", total],
["Eat", 2],
["Commute", 2],
["Watch TV", 2],
["Sleep", 7]
]);

var options = {
title: ""
};

var chart = new google.visualization.PieChart(document.getElementById("piechart"));
chart.draw(data, options);
}
});
}
google.load("visualization", "1", {packages:["corechart"], callback: drawChart});