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

无人久伴 提交于 2019-11-30 21:02:26

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.

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.

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

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"

<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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!