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

300
Visualizações
states feature with topojson in d3js

I am really new into d3 and js. I wanted to make a choropleth map of the Us showing the different states. However something is not working since i don't get any path appended to my g object. Also the console.log(states) doesn't work. I'm pretty sure this is a newbie error and due to my lacks in js/d3. However i think i must use Promise.all since i want to add another csv file later on.

Thank you in advance!

Developer Tool

Below is the Code

//Standard Method to start our d3 visualization. For Maps the margin is not that important,but we make best practices

(margin = { top: 0, left: 0, right: 0, right: 0, bottom: 0 }),
  (height = 400 - margin.top - margin.bottom),
  (width = 800 - margin.left - margin.right);

var svg = d3
  .select("#map")
  .append("svg")
  .attr("height", height + margin.top + margin.bottom)
  .attr("width", width + margin.left + margin.right)
  .append("g")
  .attr("transform", `translate(${margin.left}, ${margin.top})`);

//Read in our us Data

Promise.all([d3.json("us.json")]).then(([data]) => {
    console.log(data)
});

var projection = d3
  .geoAlbersUsa()
  .translate([width / 2, height / 2])
  .scale(100);

//create path of projection so that we can work with latidudes and longitudes
var path = d3.geoPath().projection(projection);

function ready(error, data) {

    console.log(data)

    var states = topojson.feature(data, data.objects.states).features;
    console.log(states);

    svg
     .selectAll(".state")
     .data(states)
    .enter()
    .append("path")
    .attr("class", "state")
    .attr("d", path);
    
}

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