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

122
Visualizações
D3.js with Observable, problem with event handler

I don't understand why my click event handler doesn't work. I know the event handler is running because I can see output for the three console.log() statements. The trouble is that the click event does not change the fill color. My code is all contained in one Observable notebook cell. I am using d3 version 7.3.0.

chart = {

  const height = 200;
  
  const svg = d3.create("svg")
      .attr("width", width)
      .attr("height", height);

  let my_circles = svg
    .selectAll("circle")
    .data(d3.range(10))
    .enter()
    .append("circle")
      .attr("cx", d => d * 50)
      .attr("cy", height / 2)
      .attr("r", d => Math.random() * 20)
      .attr("fill", "blue");

  my_circles
    .on("click", (event, d) => {
          console.log(event);
          console.log(d);
          console.log(d3.select(this));
          d3.select(this).attr("fill", "orange");
      });

  return svg.node();
}

Help is appeciated and thank you.

Paul

about 4 years ago · Juan Pablo Isaza
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