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

116
Views
Convierta un gráfico de barras simple en un gráfico de barras agrupadas (D3)

Tengo dos columnas de datos en mi archivo csv llamadas "beneficio" e "ingresos". Actualmente, estoy mostrando solo "beneficio" como un gráfico de barras simple. Sin embargo, deseo agrupar la otra columna de datos, es decir, "ingresos" junto con "beneficio" y convertirla en un gráfico de barras agrupadas.

Aquí están mis datos csv:

 month,revenue,profit January,123432,80342 February,19342,10342 March,17443,15423 April,26342,18432 May,34213,29434 June,50321,45343 July,54273,80002

Y aquí está mi código en Plunker:

https://plnkr.co/edit/UaL3urb5L41uN1e2?open=lib%2Fscript.js&preview

Agradecería si alguien pudiera ayudarme con esto. ¡Gracias por adelantado!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Ok, esta es una respuesta cruda, pero te permitirá desarrollar más lo que quieras. Solo necesita jugar con los anchos de las barras para acomodar dos barras por mes. https://plnkr.co/edit/K9LVNpFPmXFIGufM?preview

 const rects = g.selectAll("rect.profit") .data(data) rects.exit().remove() rects .attr("y", d => y(d.profit)) .attr("x", (d) => x(d.month)) .attr("width", 0.5 * x.bandwidth()) .attr("height", d => HEIGHT - y(d.profit)) rects.enter().append("rect") .attr("class", "profit") .attr("y", d => y(d.profit)) .attr("x", (d) => x(d.month)) .attr("width", 0.5 * x.bandwidth()) .attr("height", d => HEIGHT - y(d.profit)) .attr("fill", "grey") const rects_revenue = g.selectAll("rect.revenue") .data(data) rects_revenue.exit().remove() rects_revenue .attr("y", d => y(d.revenue)) .attr("x", (d) => x(d.month)) .attr("width", 0.5 * x.bandwidth()) .attr("height", d => HEIGHT - y(d.revenue)) rects_revenue.enter().append("rect") .attr("class", "revenue") .style("fill", "red") .attr("y", d => y(d.revenue)) .attr("x", (d) => x(d.month) + 0.5 * x.bandwidth()) .attr("width", 0.5 * x.bandwidth()) .attr("height", d => HEIGHT - y(d.revenue)) .attr("fill", "grey")
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!