Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

111
Vistas
D3 fill specific rect from many

I'm trying without luck to fill a specific rect from many in D3 with function inside the style attribute, but it's just fills all the rects with #fff (white).

I want to fill a rect if the obj of that rect (from data) is inside monitor.details array.

  .style("fill", function (d) {
          let obj = monitor.details.filter(item => item.host == d.ip && item.port == d.port && item.status == 1);

          if(Object.values(obj).length > 0) return "#fff"
          else return "#888"
        })

code snipped from:

 svg
        .selectAll()
        .data(data, function (d, i) {
          return d.host + ":" + d.port;
        })
        .enter()
        .append("rect")
        .attr("x", function (d) {
          return x(d.host);
        })
        .attr("y", function (d) {
          return y(d.port);
        })
        .attr("width", x.bandwidth())
        .attr("height", y.bandwidth())
        .style("fill", function (d) {
          let obj = monitor.details.filter(item => item.host == d.ip && item.port == d.port && item.status == 1);

          if(Object.values(obj).length > 0) return "#fff"
          else return "#888"
        })

Even more interesting, I found in DOM the element of that rect and according to DOM the fill is the actual color I picked (in the picture below I choose the red color) but it's not reflect on the screen. enter image description here

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda