I am using Kendo and Angular together. I am using Kendo Charts to display some data got from the database. I have a simple service using Angular $resource to get the data from the storage. It looks like this:
app.factory('statsData', function ($resource) {
var Stats= $resource('myadress/stats/:id', { id: '@id' });
return {
get: function (id) {
return Stats.get({ id: id});
}
}
});
So, if I execute this, I will get an array of objects that will look like this:
[
{
"name": "Books",
"amount": 200
},
{
"name": "Newspapers",
"amount": 320
},
{
"name": "Magazines",
"amount": 225
},
{
"name": "Shoes",
"amount": 400
}
]
I have a variable in my Angular controller that stores the result of the get function from the service.
$scope.chartData = statsData.get(someId);
I've declared my Kendo Chart in the HTML like this:
<div kendo-chart
k-series="[{ field: 'amount', categoryField: 'name'}]"
k-data-source="chartData">
</div>
So, the result I should get would really look like this:
The problem is that when I run the app, nothing happens. Moreover, if I change the value of the $scope.chartsData variable to a statically defined array of objects like this:
$scope.chartData = [ { "name": "Books", "amount": 200 },..];
everything works correctly and the chart is visualized properly. So, my assumption is that the problem is connected with the fact that at the time of loading the chart itself the data is still not returned from the service. How do I fix this?