Select d3 node by its datum

后端 未结 1 2003
不思量自难忘°
不思量自难忘° 2021-02-07 06:54

I’d like to select a node in a callback without using d3.select(this).

I have some code that draws a pie…

function drawPie(options) {
  opti         


        
相关标签:
1条回答
  • 2021-02-07 07:10

    You can't do this directly with .select() as that uses DOM selectors. What you can do is select all the candidates and then filter:

    d3.selectAll("g")
      .filter(function(d) { return d.data.uniqueID === myDatum.data.uniqueID; });
    

    However, it would be much easier to simply assign this ID as an ID to the DOM element and then select based on that:

    var arcs = canvas.selectAll("g.slice")
      .data(pie)
      .enter()
      .append("svg:g")
      .attr("id", function(d) { return d.data.uniqueID; })
      .attr("class", "slice");
    
    d3.select("#" + myDatum.data.uniqueID);
    
    0 讨论(0)
提交回复
热议问题