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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
freginier
Super User
Super User

Create new D3js visual

Hi all, 

 

I'm trying to create a new visual with D3JSVisual in power bi. The code bellow work with the dataset1 and dataset2 do you know how can I put power bi data on these dataset... ? Maybe not the good way ?  

I know I have to use pbi.dsv() function but I don't know how... 

 

Thank you ! 

 

      (function(d3) {
        'use strict';

        var dataset1 = [
          { count: 10 }, 
          { count: 20 },
          { count: 30 },
          { count: 40 }
        ];
        
        var dataset2 = [
          { count: 10 }, 
          { count: 40 }, 
          { count: 30 },
          { count: 40 }
        ];

        var width = 400;
        var height = 400;
        var donutWidth = 75;
        var radius1 = Math.min(width, height) / 2;
        var radius2 = radius1 - donutWidth;
        
        var color1 = d3.scale.category20();
        var color2 = d3.scale.category20c();

        var svg = d3.select('#chart')
          .append('svg')
          .attr('width', width)
          .attr('height', height);
        var svg1 = svg.append('g')
          .attr('transform', 'translate(' + (width / 2) + 
            ',' + (height / 2) + ')');
        var svg2 = svg.append('g')
          .attr('transform', 'translate(' + (width / 2) + 
            ',' + (height / 2) + ')');

        var arc1 = d3.svg.arc()
          .innerRadius(radius1 - donutWidth)  
          .outerRadius(radius1);
        var arc2 = d3.svg.arc()
          .innerRadius(radius2 - donutWidth)  
          .outerRadius(radius2);
          
        var pie = d3.layout.pie()
          .value(function(d) { return d.count; })
          .sort(null);

        var path1 = svg1.selectAll('path')
          .data(pie(dataset1))
          .enter()
          .append('path')
          .attr('d', arc1)
          .attr('fill', function(d, i) { 
            return color1(i);
          });
        var path2 = svg2.selectAll('path')
          .data(pie(dataset2))
          .enter()
          .append('path')
          .attr('d', arc2)
          .attr('fill', function(d, i) { 
            return color2(i);
          });

      })(window.d3);

 

0 REPLIES 0

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.

Top Solution Authors