Hello,
I have a project that uses xml to get data from PHP using JavaScript. I found a code to do that and I've been using it for a while now. Here is the code.
All of the variables inside the function (name, schools, churches, ......, others) are all global variables that I use to make a Google Chart. You can see it in this code.Code:function getData(communityID) { downloadUrl("chartxml.php?communityID="+communityID+"&type=infrastructure", function(data) { var xml = data.responseXML; var chartData = xml.documentElement.getElementsByTagName("info"); name = chartData[0].getAttribute("name"); schools = chartData[0].getAttribute("schools"); churches = chartData[0].getAttribute("churches"); evacs = chartData[0].getAttribute("evacs"); hospitals = chartData[0].getAttribute("hospitals"); pharmacies = chartData[0].getAttribute("pharmacies"); police = chartData[0].getAttribute("police"); fire = chartData[0].getAttribute("fire"); others = chartData[0].getAttribute("others"); }); }
The Google Chart shows with the variable "name" as the title, but the other variables (from schools to others) have no values. I checked it with FirebugLite and it showed that ALL variables have values in it. I've been stuck here for almost 4 hours now. It has no errors or whatever, FirebugLite tells me that the variables have values but it doesn't display in the chart. HELP!Code:function drawChart() { var chartTable = new google.visualization.DataTable(); var chart = new google.visualization.ColumnChart(document.getElementById('container')); chartTable.addColumn('string', 'Major Structure Type'); chartTable.addColumn('number', ''); chartTable.addRows(8); chartTable.setValue(0, 0, "Schools"); chartTable.setValue(0, 1, schools); chartTable.setValue(1, 0, "Churches"); chartTable.setValue(1, 1, churches); chartTable.setValue(2, 0, "Evacuation Centers"); chartTable.setValue(2, 1, evacs); chartTable.setValue(3, 0, "Hospitals"); chartTable.setValue(3, 1, hospitals); chartTable.setValue(4, 0, "Pharmacies"); chartTable.setValue(4, 1, pharmacies); chartTable.setValue(5, 0, "Police"); chartTable.setValue(5, 1, police); chartTable.setValue(6, 0, "Fire"); chartTable.setValue(6, 1, fire); chartTable.setValue(7, 0, "Others"); chartTable.setValue(7, 1, others); chart.draw(chartTable, {width: 700, height: 400, title: name, hAxis: {title: 'Major Structures', titleTextStyle: {color: 'red'}} }); }![]()


Reply With Quote
Bookmarks