Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix ".join is not a function" when trying join after selectAll?

Tags:

angular

d3.js

I'm trying to plot Zoomable SUnburst chart using this example: https://vizhub.com/undefined/7babe7cceb394cd1bc93157a29f8c161

The code is working in normal js but when I try to import it in Angular, it throws the following error:

ERROR TypeError: "svg.selectAll(...).data(...).join is not a function"

The line throwing error is :

const path = svg.selectAll('path')
      .data(root.descendants().slice(1))
      .join('path')
      .attr('fill', d => {
        while (d.depth > 1) { d = d.parent; }
        return color(d.data.name);
      })
      .attr('fill-opacity', d => arcVisible(d.current) ? (d.children ? 0.6 : 0.4) : 0)
      .attr('d', d => arc(d.current));

I tried adding class to svg element but it doesn't help. Removing it doesn't render the graph and every join throws the error. Also, updated to latest d3, but it doesn't help Angular version is 6.

Console log of

g.append('g')
 .selectAll('path')
 .data(root.descendants().slice(1))

enter image description here

like image 931
Upendra Sachan Avatar asked Mar 28 '19 12:03

Upendra Sachan


Video Answer


2 Answers

Replace join('path') with enter().append('path')

like image 106
Upendra Sachan Avatar answered Sep 25 '22 21:09

Upendra Sachan


I had the same issue. I fixed it by upgrading to the latest d3 version (from 5.x to 5.16).

like image 43
muyueh Avatar answered Sep 26 '22 21:09

muyueh