Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

293
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!