Angular-FusionCharts : How to fetching data from external .json file? -
ar app = angular.module('chartapp', ['ng-fusioncharts']); app.controller("mycontroller2", function($scope, $http){ $http.get('js/data.json').then(function(res,status,xhr){ $scope.countries = res.data; }); });
i want use above json chart data.
$scope.datasource = { "chart": { "caption": "column chart built in angular!", "captionfontsize": "30", "captionpadding": "25", ........ }, "data": [ ]
how can use "countries" json data chart above?
many examples declare json inside "data:[]"
, there anywhere use external .json
file?
hey can following:
angular.module('plunker', ['ng-fusioncharts']) .controller('mainctrl', ['$scope', '$http', function($scope, $http) { const chartprops = { "caption": "monthly", "xaxisname": "month", "yaxisname": "revenue", "numberprefix": "$", "theme": "fint" }; const getdatasource = (data = [], chart = chartprops) => { return { chart, data } }; $http.get('./data.json') .then(({ data }) => $scope.datasource = getdatasource(data)); $scope.datasource = getdatasource(); }]);
<!doctype html> <html ng-app="plunker"> <head> <meta charset="utf-8" /> <title>angularjs plunker</title> <script> document.write('<base href="' + document.location + '" />'); </script> <script data-require="angular.js@1.5.x" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js" data-semver="1.5.11"></script> <script src='https://static.fusioncharts.com/code/latest/fusioncharts.js'></script> <script src='https://static.fusioncharts.com/code/latest/themes/fusioncharts.theme.fint.js'></script> <script src='https://fusioncharts.github.io/angular-fusioncharts/demos/js/angular-fusioncharts.min.js'></script> <script src="app.js"></script> </head> <body ng-controller="mainctrl"> <fusioncharts id="mychartcontainer" chartid="mychart" width="600" height="400" type="column2d" datasource="{{datasource}}"></fusioncharts> </body> </html>
check plunker link live demo.
if see app.js, have commented part below - 'not-working' related implementation.
i shall looking in more detail. seems issue $observe not watching changes in object structure. stuff works when update reference. untill then, please follow above step.
thanks , lemme know in case of concern!
Comments
Post a Comment