Home forums Using CanvasJS Uncaught TypeError: Cannot read property '0' of null

Tagged: 

This topic contains 4 replies, has 2 voices, and was last updated by  isotonics 5 months, 2 weeks ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #11443

    isotonics
    Member

    Hello,

    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/

    Thanks

    #11444

    Vishwas R
    Keymaster

    Isotonics,

    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-errorType Error.

    #11450

    isotonics
    Member

    Thanks, I forgot to say that I tried this but the animation disappears. See the following animation of before and after.

    Issue Animation

    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?

    #11454

    Vishwas R
    Keymaster

    You can use when and then/done to resolve the issue. Please refer to the jsfiddle.

    #11473

    isotonics
    Member

    Thanks for you kind assistance!

    It is now fixed.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.