d3 Cannot read property 'getPropertyValue' of undefined on mouseover [duplicate]











up vote
0
down vote

favorite













This question already has an answer here:




  • Arrow function vs function declaration / expressions: Are they equivalent / exchangeable?

    2 answers



  • D3.js event listeners cannot access “this” when ES6 arrow functions are used [duplicate]

    1 answer




Trying to use a callback function .call() on mouseover to change opacity. Is this is a wrong selection? I've noticed that if I change const mouseOverFunc = d => d3.selectAll("circle") or even const mouseOverFunc = d => circle this leads all circles to show up. How to display one circle at a time? I understand that the promblem is I dont have to do groups.selectAll("circle") instead I have to append circle to groups same as I do with a path, but what I don't understand is to have access emissions d.year and d.amount for "cx" : xScale and "cy" : yScale.



Codepen



    let groups = svg.selectAll("g")
.data(dataset)
.enter()
.append("g")



groups.append("title")
.text(d => d.country)


groups
.append("path").classed("line", true)
.attr("d", d => line(d.emissions))
.style("stroke-width", d =>
d.country === "China" ? 1 : 0.2
)

let circle = groups.selectAll("circle")
.data(d => d.emissions)
.enter()
.append("circle");


circle.attrs({
"cx": d => xScale(d.year),
"cy": d => yScale(d.amount),
"r" : 3
})
.style("opacity", 0)




circle.on("mouseover", () =>
d3.select(this)
.call(mouseOverFunc));

const mouseOverFunc = selection =>
selection
.transition()
.duration(10)
.style("opacity", 1)
.style("fill", "turquoise")
.attr("r", 3)









share|improve this question















marked as duplicate by altocumulus, Quentin javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 at 11:13


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















    up vote
    0
    down vote

    favorite













    This question already has an answer here:




    • Arrow function vs function declaration / expressions: Are they equivalent / exchangeable?

      2 answers



    • D3.js event listeners cannot access “this” when ES6 arrow functions are used [duplicate]

      1 answer




    Trying to use a callback function .call() on mouseover to change opacity. Is this is a wrong selection? I've noticed that if I change const mouseOverFunc = d => d3.selectAll("circle") or even const mouseOverFunc = d => circle this leads all circles to show up. How to display one circle at a time? I understand that the promblem is I dont have to do groups.selectAll("circle") instead I have to append circle to groups same as I do with a path, but what I don't understand is to have access emissions d.year and d.amount for "cx" : xScale and "cy" : yScale.



    Codepen



        let groups = svg.selectAll("g")
    .data(dataset)
    .enter()
    .append("g")



    groups.append("title")
    .text(d => d.country)


    groups
    .append("path").classed("line", true)
    .attr("d", d => line(d.emissions))
    .style("stroke-width", d =>
    d.country === "China" ? 1 : 0.2
    )

    let circle = groups.selectAll("circle")
    .data(d => d.emissions)
    .enter()
    .append("circle");


    circle.attrs({
    "cx": d => xScale(d.year),
    "cy": d => yScale(d.amount),
    "r" : 3
    })
    .style("opacity", 0)




    circle.on("mouseover", () =>
    d3.select(this)
    .call(mouseOverFunc));

    const mouseOverFunc = selection =>
    selection
    .transition()
    .duration(10)
    .style("opacity", 1)
    .style("fill", "turquoise")
    .attr("r", 3)









    share|improve this question















    marked as duplicate by altocumulus, Quentin javascript
    Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 12 at 11:13


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite












      This question already has an answer here:




      • Arrow function vs function declaration / expressions: Are they equivalent / exchangeable?

        2 answers



      • D3.js event listeners cannot access “this” when ES6 arrow functions are used [duplicate]

        1 answer




      Trying to use a callback function .call() on mouseover to change opacity. Is this is a wrong selection? I've noticed that if I change const mouseOverFunc = d => d3.selectAll("circle") or even const mouseOverFunc = d => circle this leads all circles to show up. How to display one circle at a time? I understand that the promblem is I dont have to do groups.selectAll("circle") instead I have to append circle to groups same as I do with a path, but what I don't understand is to have access emissions d.year and d.amount for "cx" : xScale and "cy" : yScale.



      Codepen



          let groups = svg.selectAll("g")
      .data(dataset)
      .enter()
      .append("g")



      groups.append("title")
      .text(d => d.country)


      groups
      .append("path").classed("line", true)
      .attr("d", d => line(d.emissions))
      .style("stroke-width", d =>
      d.country === "China" ? 1 : 0.2
      )

      let circle = groups.selectAll("circle")
      .data(d => d.emissions)
      .enter()
      .append("circle");


      circle.attrs({
      "cx": d => xScale(d.year),
      "cy": d => yScale(d.amount),
      "r" : 3
      })
      .style("opacity", 0)




      circle.on("mouseover", () =>
      d3.select(this)
      .call(mouseOverFunc));

      const mouseOverFunc = selection =>
      selection
      .transition()
      .duration(10)
      .style("opacity", 1)
      .style("fill", "turquoise")
      .attr("r", 3)









      share|improve this question
















      This question already has an answer here:




      • Arrow function vs function declaration / expressions: Are they equivalent / exchangeable?

        2 answers



      • D3.js event listeners cannot access “this” when ES6 arrow functions are used [duplicate]

        1 answer




      Trying to use a callback function .call() on mouseover to change opacity. Is this is a wrong selection? I've noticed that if I change const mouseOverFunc = d => d3.selectAll("circle") or even const mouseOverFunc = d => circle this leads all circles to show up. How to display one circle at a time? I understand that the promblem is I dont have to do groups.selectAll("circle") instead I have to append circle to groups same as I do with a path, but what I don't understand is to have access emissions d.year and d.amount for "cx" : xScale and "cy" : yScale.



      Codepen



          let groups = svg.selectAll("g")
      .data(dataset)
      .enter()
      .append("g")



      groups.append("title")
      .text(d => d.country)


      groups
      .append("path").classed("line", true)
      .attr("d", d => line(d.emissions))
      .style("stroke-width", d =>
      d.country === "China" ? 1 : 0.2
      )

      let circle = groups.selectAll("circle")
      .data(d => d.emissions)
      .enter()
      .append("circle");


      circle.attrs({
      "cx": d => xScale(d.year),
      "cy": d => yScale(d.amount),
      "r" : 3
      })
      .style("opacity", 0)




      circle.on("mouseover", () =>
      d3.select(this)
      .call(mouseOverFunc));

      const mouseOverFunc = selection =>
      selection
      .transition()
      .duration(10)
      .style("opacity", 1)
      .style("fill", "turquoise")
      .attr("r", 3)




      This question already has an answer here:




      • Arrow function vs function declaration / expressions: Are they equivalent / exchangeable?

        2 answers



      • D3.js event listeners cannot access “this” when ES6 arrow functions are used [duplicate]

        1 answer








      javascript arrays object d3.js






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 at 0:25

























      asked Nov 12 at 0:09









      Edgar Kiljak

      367112




      367112




      marked as duplicate by altocumulus, Quentin javascript
      Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 12 at 11:13


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by altocumulus, Quentin javascript
      Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 12 at 11:13


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          Like written in altocumulus' comment, the reason is that this does work differently with arrow functions. If you are using an arrow function, you cannot use d3.select(this).



          You can solve your problem in two ways:




          • use a normal function() { }

          • use (d, i, node) => d3.select(nodes[i])


          Examples:



            circle.on("mouseover", function() => 
          d3.select(this)
          .call(mouseOverFunc));

          const mouseOverFunc = selection =>
          selection
          .transition()
          .duration(10)
          .style("opacity", 1)
          .style("fill", "turquoise")
          .attr("r", 3);


          OR



           circle.on("mouseover", (d, i, nodes) => 
          d3.select(nodes[i])
          .call(mouseOverFunc));

          const mouseOverFunc = selection =>
          selection
          .transition()
          .duration(10)
          .style("opacity", 1)
          .style("fill", "turquoise")
          .attr("r", 3);





          share|improve this answer




























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote



            accepted










            Like written in altocumulus' comment, the reason is that this does work differently with arrow functions. If you are using an arrow function, you cannot use d3.select(this).



            You can solve your problem in two ways:




            • use a normal function() { }

            • use (d, i, node) => d3.select(nodes[i])


            Examples:



              circle.on("mouseover", function() => 
            d3.select(this)
            .call(mouseOverFunc));

            const mouseOverFunc = selection =>
            selection
            .transition()
            .duration(10)
            .style("opacity", 1)
            .style("fill", "turquoise")
            .attr("r", 3);


            OR



             circle.on("mouseover", (d, i, nodes) => 
            d3.select(nodes[i])
            .call(mouseOverFunc));

            const mouseOverFunc = selection =>
            selection
            .transition()
            .duration(10)
            .style("opacity", 1)
            .style("fill", "turquoise")
            .attr("r", 3);





            share|improve this answer

























              up vote
              0
              down vote



              accepted










              Like written in altocumulus' comment, the reason is that this does work differently with arrow functions. If you are using an arrow function, you cannot use d3.select(this).



              You can solve your problem in two ways:




              • use a normal function() { }

              • use (d, i, node) => d3.select(nodes[i])


              Examples:



                circle.on("mouseover", function() => 
              d3.select(this)
              .call(mouseOverFunc));

              const mouseOverFunc = selection =>
              selection
              .transition()
              .duration(10)
              .style("opacity", 1)
              .style("fill", "turquoise")
              .attr("r", 3);


              OR



               circle.on("mouseover", (d, i, nodes) => 
              d3.select(nodes[i])
              .call(mouseOverFunc));

              const mouseOverFunc = selection =>
              selection
              .transition()
              .duration(10)
              .style("opacity", 1)
              .style("fill", "turquoise")
              .attr("r", 3);





              share|improve this answer























                up vote
                0
                down vote



                accepted







                up vote
                0
                down vote



                accepted






                Like written in altocumulus' comment, the reason is that this does work differently with arrow functions. If you are using an arrow function, you cannot use d3.select(this).



                You can solve your problem in two ways:




                • use a normal function() { }

                • use (d, i, node) => d3.select(nodes[i])


                Examples:



                  circle.on("mouseover", function() => 
                d3.select(this)
                .call(mouseOverFunc));

                const mouseOverFunc = selection =>
                selection
                .transition()
                .duration(10)
                .style("opacity", 1)
                .style("fill", "turquoise")
                .attr("r", 3);


                OR



                 circle.on("mouseover", (d, i, nodes) => 
                d3.select(nodes[i])
                .call(mouseOverFunc));

                const mouseOverFunc = selection =>
                selection
                .transition()
                .duration(10)
                .style("opacity", 1)
                .style("fill", "turquoise")
                .attr("r", 3);





                share|improve this answer












                Like written in altocumulus' comment, the reason is that this does work differently with arrow functions. If you are using an arrow function, you cannot use d3.select(this).



                You can solve your problem in two ways:




                • use a normal function() { }

                • use (d, i, node) => d3.select(nodes[i])


                Examples:



                  circle.on("mouseover", function() => 
                d3.select(this)
                .call(mouseOverFunc));

                const mouseOverFunc = selection =>
                selection
                .transition()
                .duration(10)
                .style("opacity", 1)
                .style("fill", "turquoise")
                .attr("r", 3);


                OR



                 circle.on("mouseover", (d, i, nodes) => 
                d3.select(nodes[i])
                .call(mouseOverFunc));

                const mouseOverFunc = selection =>
                selection
                .transition()
                .duration(10)
                .style("opacity", 1)
                .style("fill", "turquoise")
                .attr("r", 3);






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 12 at 11:10









                thibautg

                9341410




                9341410















                    Popular posts from this blog

                    Xamarin.iOS Cant Deploy on Iphone

                    Glorious Revolution

                    Dulmage-Mendelsohn matrix decomposition in Python