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

134
Visualizações
D3 linear scale domain mapping path elements to JSON

I have the following JSON data that I need to pass to my D3 function to fill the colours of some blocks on a SVG:

{
  "_116": {
    "scanned": 234,
    "sold": 295
  },
  "_119": {
    "scanned": 175,
    "sold": 207
  },
  "_210": {
    "scanned": 133,
    "sold": 235
  },
  "_118": {
    "scanned": 136,
    "sold": 189
  },
  "_123": {
    "scanned": 63,
    "sold": 160
  },
  "_106": {
    "scanned": 38,
    "sold": 66
  },
  "_108": {
    "scanned": 184,
    "sold": 242
  },
}

The keys in this data correspond with the path id's in my rendered SVG as such:

<path id="_116" serif:id="116" d="M75,22c0,-1.105 0.895,-2 2,-2l31,0c1.105,0 2,0.895 2,2l0,25c0,1.105 -0.895,2 -2,2l-31,0c-1.105,0 -2,-0.895 -2,-2l0,-25Z" style="fill:#fff;fill-rule:nonzero;"/>

I want to use D3 to add the style fill for of all of these path elements based on the data passed in on a linear scale.

Here is what I have so far:

let color = d3.scaleLinear()
            .domain([1,100])
            .range(["white", "green"]);

d3.select("path#_116")
         .style('fill',function(d,i) {
                 return color(10);
          });

This would just fill the value of a single path element with id _116 with the value of 10 with the linear scale of 1 - 100.

How would I make this work so that I map all of my path elements with the data in my JSON based on the keys and so that it uses the domain range of [0 - sold] and the value of the fill as the scanned attribute in my data?

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