Reputation: 193
How would I get my 'total' variable in my xmlParser function to display as a variable for Google Charts.
Upvotes: 1
Views: 901
Reputation: 26340
You need to move the AJAX call inside the drawChart function and populate the data from there. Here's one way of doing it:
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});
Upvotes: 1