Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
filipwydra
Frequent Visitor

Multi parent hierarchy - custom visual D3.js

Hello Guys !

 

I create hierarchy table and what I want to achieve is something like this below:

 

filipwydra_0-1636632720500.png

 

I know how to build hierarchy level for two categories and draw it, but I have a problem with 3 or more categories. 

My dataset is flat array of objects. Every object has id and parentId. I'm using d3.stratify() to make hierarchy nodes. It works properly but once I add third category which has two or more parents it crush. I found somewhere that hierarchy where children have many parents is not hierarchy anymore but graph. Is it right ?

 

 This is my stratify function:

      const root = d3
        .stratify()
        .id(function (d: any) {
          return d.name;
        })
        .parentId(function (d: any) {
          return d.parentId;
        })(items);

 

This is my dataset transform when there is 3 categories: 

    yAxis.map((d, i) => {
      if (yAxis.length === 3) {
        if (i === 2) {
          const children = data.filter(
            (d) => d.name === d.yAxis[d.yAxis.length - 1]
          );
          uniqArray.push(children);
        } else if (i === 1) {
          const children = data.filter((d) => d.name === d.yAxis[1]);

          const filteredChildren = children.filter(function (a) {
            var key = a.name + "|" + a.parentName;
            if (!this[key]) {
              this[key] = true;
              return true;
            }
          }, Object.create(null));

          uniqArray.push(filteredChildren);
        } else {
          const children = data.filter((d) => !d.parentId);
          uniqArray.push(_.uniqBy(children, (d) => d.name));
        }

        return [..._.flatten(uniqArray), { name: "root" }];
      }
    });

    return yAxis.length > 1
      ? [..._.flatten(uniqArray), { name: "root" }]
      : [...data, { name: "root" }];

 

Did you ever face that problem ? Or maybe you have some solution.

 

I will be grateful for any advice how to do this.

 

Thanks!

0 REPLIES 0

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors
Top Kudoed Authors