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

235
Views
D3 - ¿Cómo puedo poner un SVG en un DIV a través de una función?

Para reutilizar el código, quiero poner mi SVG en una función y llamarlo según sea necesario. Una vez que selecciono el DIV, ¿cuál es la construcción adecuada para representar el SVG dentro de él?

 ... if (intLocations.includes(comm.location)) { const intActivities = d3.select('div#intActivities') intActivities.append(Pill(comm)) } else { const extActivities = d3.select('div#extActivities') actActivities.append(Pill(comm)) } ... function Pill(comm) { const svgNode = d3.create('svg') svgNode .attr('width', 100) .attr('height', 100) .append('g') // More code to draw the figure using comm data. return svgNode; }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

intActivities.append(() => Pill(comm).node()) debería funcionar. Aquí hay un ejemplo:

 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script src="https://d3js.org/d3.v7.js"></script> </head> <body> <div id="my-div"></div> <script> d3.select('#my-div').append(() => square().node()); function square() { const svg = d3.create('svg') .attr('width', 100) .attr('height', 100); svg.append('rect') .attr('width', 100) .attr('height', 100) .attr('fill', 'navy'); return svg; } </script> </body> </html>

Alternativamente, puede pasar a su función Pill la selección div a la que desea agregarla.

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!