d3.json: “Uncaught TypeError: Cannot read property 'children' of undefined”

后端 未结 5 2120
面向向阳花
面向向阳花 2021-01-05 16:14

I am trying out d3 as a tool for representing biological data.

I am trying to open the following example in my chrome browser so that I can understand how it works

相关标签:
5条回答
  • 2021-01-05 16:22

    In order to get it to work I had to replace the line

    d3.json("flare.json", function(error, root) {
    

    with

    d3.json("flare.json", function(root) {
    

    I used my intuition here and I still do not understand how it worked on the example website and not mine, or what the true significance of my change in the code is. If you know how to answer this in a more in-depth fashion, please contribute and I will accept your answer.

    0 讨论(0)
  • 2021-01-05 16:23

    It's because the returned json object is received by the first parameter of the function. It might because of the versions of d3.

    0 讨论(0)
  • 2021-01-05 16:28
    <script>
            function liveProject() {
               var  a=200;
               this. x=600;
               this. y=300;
               this. z= function () {
                   return this.x+this.y;
               }
            }
            var lp=new liveProject();
            document.write(lp.z());
        </script>
    
    0 讨论(0)
  • 2021-01-05 16:30

    Had the same exact error. The solution is pretty simple: You are not providing a JSON object array. You said your JSON begun as follows:

    { "name": "flare", "children": [ ...

    Please change so change is begins as follows:

    [{ "name": "flare", "children": [ ...}]

    That way D3 will be able to locate the "first child"

    0 讨论(0)
  • 2021-01-05 16:42

    The code is from d3.v3 but it's pointing to d3.v2, which does not use the error call in the d3.json function.

    0 讨论(0)
提交回复
热议问题