Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

255
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda