I have a template that uses jQuery/AJAX to pull some data. Getting the data isn't an issue, but I can't seem to use it in a way that GoogleVis wants. The line causing problems for me is mapdata.addRows([gapidata]);. It seems there's an issue with the array but I'm not sure how to fix it. Any help is greatly appreciated!
The jQuery/AJAX I'm using:
var gapidata = new Array();
$.ajax({
url: "inc/index.gapi.inc.php",
cache: false,
dataType: "text",
success: function(html){
gapidata = html;
}
});
The data I get from the AJAX call:
['Korea, Republic of', 50],['Japan', 38]
The code I use to display the data:
// Geo Map Chart
var mapWidth = Math.round(((screenWidth / 12) * 10) * 0.8);
var mapHeight = Math.round(mapWidth * 0.5);
$('#dashboard-visit-map').width(mapWidth*1.1);
$('#dashboard-visit-map').height(mapHeight*1.1);
var mapdata = new google.visualization.DataTable();
mapdata.addColumn('string','Country');
mapdata.addColumn('number','IPs Listed');
mapdata.addRows([gapidata]);
var geochart = new google.visualization.GeoChart(document.getElementById('dashboard-visit-map'));
geochart.draw(mapdata, {width: mapWidth, height: mapHeight,backgroundColor: { fill:'transparent' }});
Currently the map doesn't populate with any data. If I remove the brackets around gapidata I receive the following error on my JavaScript console:
Uncaught Error: Row given with size different than 2 (the number of columns in the table).
I just normalized my data frame before calling the rendering function; it worked fine for me.
Normalizes data frame:
data <- as.data.frame.matrix(data)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With