Can anyone help me with using Google's geochart to draw a map with stats? I'm struggling to figure out how to combine my 2 arrays.
Here is the data I receive from the server:
[["DZ", 0], ["EG", 0], ["EH", 0], ...
and I need to put it into this array:
geoArray = [["Country", "Clicks"]];
Here is my current code:
async function drawRegionsMap() {
geoArray = [["Country", "Clicks"]];
await fetch(`http://127.0.0.1:80/grab`, {
method: "post",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({
token: token,
key: "grab_geo_stats",
}),
})
.then((response) => {
return response.json();
})
.then((data) => {
for (var i = 0; i < data.message.length; i++) {
geoArray.push(data.message[i]);
}
var data = google.visualization.arrayToDataTable(geoArray);
var options = {
legend: "none",
backgroundColor: "transparent",
datalessRegionColor: "#62bcfc",
colors: "#527aff",
width: "695",
height: "390",
interactive: true,
tooltip: {
isHtml: true,
},
};
chart = new google.visualization.GeoChart(
document.getElementById("regions_div")
);
chart.draw(data, options);
});
}
I want the final result to look like this:
[
['Country', 'Popularity'],
['Germany', 200],
['United States', 300],
['Brazil', 400],
['Canada', 500],
['France', 600],
['RU', 700]
]