Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

270
Views
d3 draggable threshold, d.x is undefined

https://jsfiddle.net/wiremanj20/cfsh4gvo/150/

d3.selectAll("circle")
        .attr("fill", function(d) {
      console.log(linePosition)
     // console.log(attr("cx"));
      if (d.x <=(linePosition)) {
        return lowColor 
      } else {
        return highColor 
      }
      })
      ;
  

On line 133, my if statement is not working. d.x is always undefined and I am unsure why. The goal is to make it so that the graph points change color when the threshold is in front of them. thank you

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

d is not an object, is an array that has two values. That's why if you use d.x the output is undefined, because is not an object that contains a x property.

To solve you problem, you have to replace d.x to d[0] (is the first element of the array).

d3.selectAll("circle")
  .attr("fill", function (d) {
    console.log(linePosition)
    // console.log(attr("cx"));
    if (d[0] <= (linePosition)) {
      return lowColor
    } else {
      return highColor
    }
  })
  ;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!