Soy realmente nuevo en d3 y js. Quería hacer un mapa de coropletas de los Estados Unidos mostrando los diferentes estados. Sin embargo, algo no funciona ya que no se adjunta ninguna ruta a mi objeto g. Además, console.log (estados) no funciona. Estoy bastante seguro de que este es un error de novato y debido a mis deficiencias en js/d3. Sin embargo, creo que debo usar Promise.all ya que quiero agregar otro archivo csv más adelante.
¡Gracias de antemano!
Herramienta para desarrolladores
A continuación se muestra el código
//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); }