Comments (12)
I actually got to fix the problem myself, the solution was ridiculous and made me feel retarded.
The structure of the 'data' array should be something like:
data = [[1, 2, 3, 4], [8, 7, 6, 5] ]
Problem was that I had only one series, not more, therefore from the backend I sent a response looking like:
response = [1, 2, 3, 4]
Whereas the correct version would have been
response = [[1, 2, 3, 4]]
And well, the solution was to simply set:
scope.data = [response]
I'm pretty sure I'm the only one with this problem as it's ridiculously obvious however, maybe, just maybe someone else has encountered this as well and is struggling with it so that's why I took the time to write it.
All the best!
from angular-chartjs.
I believe I had a similar problem. When requesting data in an asynchronous callback, I get the error TypeError: Cannot read property 'datasets' of undefined
This can be reproduced in the test code app.js by putting $scope.activeData = $scope.lineChartData in a setTimeout.
from angular-chartjs.
I believe this is solved by defining the datasource on the scope immediately, then "populating" it as the async callback runs.
datasource: {
labels: [],
datasets: []
}
from angular-chartjs.
I believe that is true. Regardless I'll improve that in a future release. Thanks for the info, closing for now. Please re-open if new information.
from angular-chartjs.
Hi,
is it possible to give morge information about this section? I am trying to fetch data from a JSON file with an $http-function in Angularjs but I received the same error as described above. In my console.log ($scope.date = data;) I receive a succes message but my data doesn't display in my html.
Can someone help me with this problem.
Big thanks.
from angular-chartjs.
I'm facing the same error.
<canvas class="chart chart-bar" chart-data="chart.data" chart-labels="chart.labels">
app.controller('dashboardController', function($scope, Sales) {
$scope.chart = {
labels: [],
data: []
}
Sales.get().then(function(data) { // async data call via REST API
for (i = data.length - 1; i >= 0; i--) {
date = moment().month(data[i].month).year(data[i].year).format('MMM YYYY');
$scope.chart.labels.push(date);
$scope.chart.data.push(data[i].total);
}
});
});
As you can see I've already initialised the two arrays at the top of the controller, but am still getting the same cannot read property 'length' of undefined
error
from angular-chartjs.
Having the same issue. Any solutions?
from angular-chartjs.
Thanks Alex.. I got this error and cleared it now because of your comment
from angular-chartjs.
Haha! Good to know
from angular-chartjs.
Still facing the same issue, don't know if you can provide details about how you solved it. I want to provide a barchart and still running into same length issue, if i provide response, the data are blank.
thanks
from angular-chartjs.
@dfemo: You are probably trying to access an undefined array somewhere in your code. Make sure to define the structure of your data immediately, then populate the structure when the data arrives.
You can't do something like data.item.properties.length
without doing something like this first:
var data = {
item: {
properties: []
}
};
from angular-chartjs.
Thanks, Alex. I didn't notice the array of arrays, and hit the same error as the OP. Your post helped me fix it.
from angular-chartjs.
Related Issues (20)
- ReferenceError: Chart is not defined at postLink HOT 3
- setting scaleStepWidth dynamically? HOT 4
- How do you use the 'advanced' features, specifically .generateLegend()? HOT 4
- Dynamically updated values don't work on pie charts HOT 2
- Issues installing via Bower and Grunt's wiredep HOT 6
- Installing via Bower (lastest version) cannot find src file HOT 2
- How i use ng-repeat with this directive?
- How i use ng-repeat with this directive?
- Chart not updating HOT 7
- Can't use dynamic data HOT 2
- Legend template HOT 5
- Demo url not working HOT 2
- Setting up a custom width HOT 2
- How to show labels? HOT 2
- options are not applied to pie chart
- component breaks when using uglify
- Error: c[e] is not a function HOT 1
- cant seem to be able to enable tooltips in any of the charts? HOT 2
- Chart increasing height infinitely when "autofit=true" HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-chartjs.