mercredi 2 août 2017

D3.js TreeMap - Error: attribute width: Expected length, "NaN"

I'm trying to create a treemap diagram in D3 in ReactJS, below is my code, I'm getting this error but can't figure out why:

Error: attribute width: Expected length, "NaN".

    const chart = d3.select(this.node)

    const treeMap = d3.treemap()
        .size(this.state.width, this.state.height)

    d3.json("treemap.json", (error, data) => {
        if (error) throw error;
        console.log(data)
        const root = d3.hierarchy(data)
            .sum((d) => { return d.size })

        treeMap(root);
        console.log(root)

        const cell = chart.selectAll("g")
            .data(root.leaves())
            .enter()
            .append("g")

        cell.append("rect")
            .attr("id", (d) => { return d.data.id; })
            .attr("width", (d) => { return d.x1 - d.x0; })
            .attr("height", (d) => { return d.y1 - d.y0; })

Any help would be really appreciated. Thanks!




Aucun commentaire:

Enregistrer un commentaire