>
> I'm using the the GeoCharts for US states and I'm trying to dynamically
> load table data from a variable. I've pushed all the data I need from my
> API into an empty array but I can't seem to find a way to call that
> variable to populate the table data. Has anyone found the solution for
> this or a workaround?
>
Here's what I got so far ...
```google.charts.load('current', { packages: ['geochart'] });
google.charts.setOnLoadCallback(mapUS);
function mapUS() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'State');
data.addColumn('number', 'Number of Things');
// Need to load data here somehow
var options = {
region: 'US',
resolution: 'provinces',
displayMode: 'regions',
colorAxis: {
colors: ['#0CEFFF', '#033C40']
},
legend: 'none'
};
var states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',
'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii',
'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky',
'Louisiana','Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota',
'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New
Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina',
'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode
Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah',
'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin',
'Wyoming'];
var statesArr = [];
states.map(function(state) {
$.ajax({
headers: { Accept: 'application/json' },
type: 'GET',
url: URL + state + KEY,
crossDomain: true,
beforeSend: function(xhr) {
xhr.withCredentials = true;
}
}).done(function functionName(state, sum) {
sum = state.totalResults;
state = state.data[0].region;
statesArr.push({c:[{v: state}, {v: sum}]});
}).fail(function(err) {
console.log(err);
});
});
var chart = new
google.visualization.GeoChart(document.getElementById('beerMapUS'));
chart.draw(data, options);
}```
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-visualization-api/cfd4b4f4-478e-43c3-9777-1889c4456554%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.