Kostya Tresko
Kostya Tresko

Reputation: 854

d3 select from angular

I have a directive in angular 1.x, in which I instatiate d3 pie chart. I want to add some text to it so in link function I wrote:

 var svg = d3.select(element).selectAll('svg');
 var donut = svg.selectAll('g.nv-slice').filter(
                                    function (d, i) {
                                    return i == 0;
                                }
                            );
 donut.insert('text', 'g')
      .text('Line One')
      .attr('class', 'middle')
      .attr('text-anchor', 'middle')
      .attr('dy', '-.55em')
      .style('fill', '#000');

But I get an error: Uncaught TypeError: n.querySelectorAll is not a function There is no such error if I get svg as var svg = d3.select('svg');, but I want d3 to select only from current directive element

Fiddle: http://jsfiddle.net/bnUY9/26/

Upvotes: 1

Views: 3398

Answers (1)

Kostya Tresko
Kostya Tresko

Reputation: 854

I resolved my problem by using var selection = d3.selectAll($element);

http://jsfiddle.net/bnUY9/27/

Upvotes: 2

Related Questions