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

257
Views
Cambiar color según el conjunto de datos (d3)

Tengo dos conjuntos de datos d1 y d2 de la siguiente manera:

 const d1 = [ {group: "H", value: 6}, {group: "I", value: 2}, {group: "M", value: 3} ]; const d2 = [ {group: "H", value: 1}, {group: "I", value: 12}, {group: "M", value: 2} ];

y una función llamada makethisgraph donde los "datos" que se envían son d1 y d2 según un botón en el que hago clic. En esta función, según los datos que selecciono, las barras cambian para coincidir con los valores. Quiero hacerlo de tal manera que si selecciono d1, el color de la barra cambie a rojo y si selecciono d2, se vuelva verde

 function makethisgraph(data) { var u = svg.selectAll("rect") .data(data) u .enter() .append("rect") .merge(u) .transition() .duration(1000) .attr("x", function(d) { return x(d.group); }) .attr("y", function(d) { return y(d.value); }) .attr("width", x.bandwidth()) .attr("height", function(d) { return height - y(d.value); }) .attr("fill", function(d, i) { // if ( data = d1) // { // return "red" // } // else // { // return "green" // } return "blue" });

Intenté escribir si los datos que obtuve son d1, entonces será rojo pero no funciona. ¿Hay alguna otra manera de resolver esto?

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

0

Agregue un parámetro de color para hacer makethisgraph :

 function makethisgraph(data, color) { ... u.enter() ... .attr("fill", color); } ... makethisgraph(d1, 'red'); makethisgraph(d2, 'green');
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!