我想要做的是將JSON對象讀入我的$ angularMap.data,然後在Google GeoMap上顯示相關國家。我能夠編寫需要使用的JSON對象,但對於我的生活,我無法弄清楚如何將json對象連接到$ scope。Google GeoMaps JSON
var app = angular.module('myApp', ['googlechart']);
app.controller('MainCtrl', function ($scope, $http) {
$http.get('js/data.json')
.then(function(jsonData){
$scope.country=jsonData.data.cols[0].label;
console.log(jsonData.data.cols[0].label)
});
var angularMap = {};
angularMap.type = "GeoChart";
angularMap.data = [
['Country', 'Amount'],
['Germany', 200],
['United States', 300],
['Brazil', 400],
['Canada', 500],
['France', 1600],
['Russia', 700],
['Eygpt', 900],
['Pakistan', 900]
];
angularMap.options = {
width: 600,
height: 300,
colorAxis: {colors: ['#00FF00']}
// displayMode: 'regions'
};
var legendName = "eventTypePerDay";
var timerVar = setInterval(myTimer, 350);
function myTimer() {
var legend = document.getElementById("legend").innerHTML = legendName;
}
$scope.chart = angularMap;
});
JSON
{
"cols": [{
"id": "",
"label": "Country",
"pattern": "",
"type": "string"
}, {
"id": "",
"label": "Amount",
"pattern": "",
"type": "number"
}],
"rows": [{
"c": [{
"v": "United States",
"f": null
}, {
"v": 300,
"f": null
}]
}, {
"c": [{
"v": "Russia",
"f": null
}, {
"v": 500,
"f": null
}]
}, {
"c": [{
"v": "Canada",
"f": null
}, {
"v": 100,
"f": null
}]
}, {
"c": [{
"v": "Brazil",
"f": null
}, {
"v": 1000,
"f": null
}]
}, {
"c": [{
"v": "Germany",
"f": null
}, {
"v": 200,
"f": null
}]
}]
}
http://plnkr.co/edit/JHdUuyNjIVKookAwYmTq?p=preview
正好!謝謝! – user2402107