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

121
Views
SVG no se muestra en la pantalla, el registro de la consola muestra "falso", lo que sugiere que se rechazó la promesa

No estoy seguro de por qué mi SVG no se muestra en la pantalla. El registro de la consola dice "falso", lo que supongo que significa que se rechazó una promesa

Este es mi archivo TS

 export class PieChartComponent implements AfterViewInit { //other initializations removed for brevity convertedData: Map<string, number> = new Map(); ngAfterViewInit() { d3.csv('app/data/data.csv').then((data) => { data.forEach((d) => { this.convertedData.set(d['name'], Number(d['age'])); }); }); this.svg = d3 .select('#canvas-area') .append('svg') .attr('width', 400) .attr('height', 400); this.circles = this.svg.selectAll('circle').data(this.convertedData); this.circles .enter() .append('circle') .attr('cx', (d, i) => i * 50 + 50) .attr('cy', 250) .attr('r', (d) => 2 * d[0]) .attr('fill', (d) => { if (d[1] == 'Jessica') return 'blue'; return 'red'; }); } }

Y, este es mi archivo HTML:

 <div id="canvas-area"></div>

Mi archivo data.csv básicamente tiene esto:

 name,age Tony,10 Jessica,12 Andrew,9 Emily,10 Richard,11
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

d3.csv() es una promesa, pero no está esperando que se complete, por lo que es muy probable que this.convertedData esté vacío cuando intente usarlo.

Necesitas actualizar tu código a algo como esto:

 async ngAfterViewInit() { await d3.csv('app/data/data.csv').then((data) => { data.forEach((d) => { this.convertedData.set(d['name'], Number(d['age'])); }); }); // the rest of your code }
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!