Home › forums › Using CanvasJS › Uncaught TypeError: Cannot read property '0' of null
This topic contains 4 replies, has 2 voices, and was last updated by Anonymous 1 year, 9 months ago.
I have a graph, it displays correctly, but is showing an error in the console, Uncaught TypeError: Cannot read property ‘0’ of null
Could you have a look and tell me what is wrong with the code or maybe this is a bug somewhere.
I have narrowed it down to the showInLegend: true, code, but I cannot fix it.
Link to page: http://nunjv.xyz/stats/
Under Chart-options you are initializing dataPoints to null, because of which you are getting type error. You can set dataPoints to an empty array to overcome this type-error.
Thanks, I forgot to say that I tried this but the animation disappears. See the following animation of before and after.
The underlying issues here is that because getJSON is asynchronous, it does not work with windows.onload and the graph remains empty. So I have to get the JSON data before I render the graph.
Is there a better way to handle this?
You can use when and then/done to resolve the issue. Please refer to the jsfiddle.
Thanks for you kind assistance!
It is now fixed.
You must be logged in to reply to this topic.