Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

236
Vistas
easily get text appended to a node on d3 graph

I can't get my head around the d variable conventionnally used in d3.

Once the graph is generated, i'd like to pass the text value as a variable on click (or at least log it on console).

        const node = svg
          .append("g")
          .attr("stroke", "#fff")
          .attr("stroke-width", 1.5)
          .selectAll("circle")
          .data(nodes)
          .join("circle")
          .attr("r", 15)
          .attr("stroke", "none")
          .style("fill", "none")
        const text = svg
          .append("g")
          .selectAll("text")
          .data(nodes)
          .join("text")
          .text((d) => d.word)
          .style("cursor", "pointer")
          .attr("text-anchor", "middle")
          .attr("alignment-baseline", "middle");
          .on("click", (d) => console.log(/*value of text here as string*/))
        node.append("title").text((d) => d.id);

I tried console.log(d) and it displays a whole load of infos without an easy path to the value of the clicked text.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I don't know if it's the fastest way but good enough I guess

(d.path[0].firstChild.data)
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda