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

209
Vistas
d3.js heatmap change specific rect color in react js

I am using d3.js to display over 10k grid, and each rect has own color. But there are several specific rect info which comes from backend API, I need to change those specific rects' color.

My code is:

const ref = useD3(
    (svg) => {

      const tooltip = d3.select(".tooltip");

      const mouseleave = function(d) {
        tooltip.style("opacity", 0);
        d3.select(this)
          .style("stroke", "#FFF")
          .style("stroke-opacity", 0.3)
          .style("stroke-width", 1)
          .style("opacity", "1");
      };
    
      svg.select(".main-area")
        .selectAll("rect")
        .data(data1, function(d) {return 'price: ' + d.price;})
        .enter()
        .append("rect")
          .attr("x", d => d.x)
          .attr("y", d => d.y)
          .attr("width", d => d.width )
          .attr("height", d=> d.height )
          .style("stroke-width", 1)
          .style("stroke", "#FFF")
          .style("stroke-opacity", 1)
          .style("opacity", 1)
          .style("cursor", "pointer")
        .on("mouseover", mouseover)
        .on("mouseleave", mouseleave)
        .on("mousemove", mousemove)
        .on("click", mouseclick);
    },

    [data1]
  );

As you can see above code, I appended 'rect' to ".main-area". After this, I want to change specific rects' color when event happens.

Here is what I've done.

// on event... // custom D3

var svg = d3.select('svg');
       svg.select(".main-area")
          .select("rect")
          .attr('x', decX)
          .attr('y', decY)
          .attr('fill', "#ef32d3"); 

But it doesn't work.

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