0

Using d3.js to create a bubble chart. Wanting to hover over a certain bubble and change the style. In the second variable I'm wanting to hover over the current node(circle) but getting error 'Cannot read property 'setProperty' of undefined. When console.log('d') I retrieve the current node(circle) that is passed but cannot style that either. d3.select(this) is useless. What am I missing?

 chart = () => {

    var diameter = document.getElementById("test").offsetHeight;
    var bubble = d3
      .pack(this.state.data)
      .size([diameter, diameter])
      .padding(20);

    var svg = d3
      .select("#test")
      .append("svg")
      .attr("width", diameter)
      .attr("height", diameter)
      .attr("class", "bubble");

    var nodes = d3.hierarchy(this.state.data).sum(function(d) {
      return d.subscribers;
    });

    var node = svg
      .selectAll(".node")
      .data(bubble(nodes).descendants())
      .enter()
      .filter(function(d) {
        return !d.children;
      })
      .append("g")
      .attr("class", "node")
      .attr("transform", function(d) {
        return "translate(" + d.x + "," + d.y + ")";
      });

    node.append("title").text(function(d) {
      return d.data.subscribers;
    });



    node
      .append("circle")
      .attr("r", function(d) {
        return d.r;
      })
      .style("fill", "c81912")
      .on("mouseover", (d,i) => {

      })

    node
      .append("text")
      .attr("dy", ".2em")
      .style("text-anchor", "middle")
      .text(function(d) {
        return d.data.service;
      })
      .attr("font-family", "sans-serif")
      .attr("font-size", function(d) {
        return d.r / 5;
      })
      .attr("fill", "black");

    d3.select(this.frameElement).style("height", diameter + "px");
  };
jackstride
  • 53
  • 8
  • Can you elaborate more about your issue, a code snippet would help addressing your issue. – ROOT Feb 05 '20 at 09:36
  • Because you are using an arrow function in your d3 event listener, `this` doesn't refer to the selection, but the function itself. Try using: `.on('mouseover', (d,i,e) => { let selection = d3.select(e[i]) })` – Lazaro Gamio Feb 07 '20 at 01:25

0 Answers0