Dynamically Load XML data

105 views
Skip to first unread message

Craig Bridges

unread,
Feb 29, 2012, 2:42:24 PM2/29/12
to Google Visualization API
Hi,

I am trying to dynamically load data in to a graph but when i add the
lines

data.setValue(x, 0, new Date(year, month, day));
data.setValue(x, 1, numQueries);

In the ajax call it hangs and will not work. When I take those lines
out my data is returned as expected and the graph displays but says
there is no data. here is what i am working with:

function drawVisualization() {


var data = new google.visualization.DataTable();
data.addColumn('date', 'Date');
data.addColumn('number', 'Number of Users');
var numOfRows = 2;
data.addRows(numOfRows);




$.ajax({
url: "/WebServiceURL",
type: "GET",
dataType: "xml",
data: "inputReportName=S,N",
success: function(xml) {


var x = 0;
$(xml).find("UsageMetricsDTO").each(function()
{
var date = $(this).find('logDate').text();

var dateArray = date.split('-');
var year = dateArray[0];
var month = dateArray[1];
var day = dateArray[2];
var numQueries = $(this).find('numOfQueries').text();
if(x == 1){
day = 02;
}
data.setValue(x, 0, new Date(year, month, day));
data.setValue(x, 1, numQueries);
alert("year: "+year+" <br/>month: "+month+"<br/> day: "+day
+"<br/>numqueries: "+numQueries+"<br/>x: "+x);
x++;

});



},
error: function() {
$("#tabs-1").writeErrorMessage();
}

});
var annotatedtimeline = new
google.visualization.AnnotatedTimeLine(
document.getElementById('visualization'));
annotatedtimeline.draw(data, {'displayAnnotations': true});
}

Any ideas why this is happening?

Jinji

unread,
Mar 1, 2012, 8:27:50 AM3/1/12
to google-visua...@googlegroups.com
I personally have no idea... Can you post a complete page that demonstrates this issue (preferably a link to such a demo)?


--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To post to this group, send email to google-visua...@googlegroups.com.
To unsubscribe from this group, send email to google-visualizati...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.


asgallant

unread,
Mar 1, 2012, 9:59:03 AM3/1/12
to google-visua...@googlegroups.com
Your data table only has two rows in it.  If your data returned by the AJAX call has more than two rows, the script would bomb on the third row.  You might consider either adding a row immediately before setting the values or passing the values in an array to the addRow method, ie:

data.addRow([new Date(year, month, day), numQueries]);

I believe you will also need to parse the numQueries value as a number, as the jQuery#text method returns a string, which the DataTable won't accept as valid input in a number column; you could use something like this to make it work:

var numQueries = parseInt($(this).find('numOfQueries').text());  
Reply all
Reply to author
Forward
0 new messages