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

297
Vistas
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 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