Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

322
Visualizações
D3 wrapping text legends

I am using legends for d3 charts. Below is code -

 var padding = { left:50, right:100, top:30, bottom:30 };


    var legend = svgColorCode.selectAll(".legend")
      .data(keyText) //.filter(x=>x!="Completed On Time")
      .enter().append("g")
      .attr("class", "legend")
      .attr("transform", function (d, i) { return "translate(" + (((keys.length - (i)) * -25) + (i == 0 ? 0 : (i == 1 ? 60 : (i == 2 ? 90 : (i == 3 ? 100 : 0))))) + "," + (height - 190) + ")"; })
      .attr("fill", function (d, i) { return colors[i]; });

    legend.append("rect")
      .attr("x", (x, i) => (padding.top * 2 + labHeight * (i)) + 40)
      .attr("width", 18)
      .attr("height", 18)
      .style("fill", function (d, i) { return colors[operationalKeys[i]]; })

    legend.append("text")      
      .attr("x", (x, i) => (padding.top * 2 + labHeight * i) + 60)
      .attr("y", 9)
      .attr("font-size", "0.65rem")
      .attr("dy", ".35em")      
      .style("text-anchor", "start")
      .text(function (d) { console.log("d");console.log(d); return d.replace("&nbsp","\n"); })
      .call(wrap)
      ;

Here I have long texts for legends and small place to accomodate it. I want to wrap the text for legends.

For that I followed this SO answer and used wrap method. But seems wrap is not working in this case.

How can I wrap my text for legends in d3 js?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda