Kevin Waterson
Kevin Waterson

Reputation: 837

TreeMap not working with JSON

I have a treemap which works fine with csv data, however, when I change the source to json, the tree does not appear. Is the problem with the json format?

        d.company.forEach( function ( obj )
    {
            d.id = +obj.id;
            d.value1 = +obj.value1;
            d.value2 = +obj.value2;
    });

plnkr: https://plnkr.co/edit/PPLxOC6zxsnj6I3jCn4H?p=preview

Upvotes: 0

Views: 111

Answers (1)

Gerardo Furtado
Gerardo Furtado

Reputation: 102174

Unlike d3.csv and d3.tsv, d3.json does not accept an accessor function. In your case, the accessor function is cast:

d3.json("data.json", cast, main)

So, instead of using an accessor function, remove cast:

d3.json("data.json", main)

And do whatever cast does with your data inside your main function.

Here is the API showing the differences between d3.csv and d3.json: https://github.com/d3/d3-request/blob/master/README.md .

Upvotes: 1

Related Questions