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

234
Views
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 answers
Answer question

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 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!