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

130
Views
d3 svg map with 2 data

I am using d3 svg map and I have 2 data, one for map, and another my custom data to plot the data points on the map. This is the map data const mapDataUrl = 'https://d3js.org/world-50m.v1.json' I want to color the country which has the data point in my custom data.

Below is the sample part of my custom data to plot the data points like here the country is the US, so I want to fill some color to US.

"features": [
    {
      "properties": {
        "ip": "8.8.8.8",
        "loc":"37.4056, -122.0775",
        "name": "US",
        "country": "US",
        "reclong": "-122.0775",
        "year": "1880-01-01T00:00:00.000",
        "id": "1",
        "reclat": "37.4056"
      }
    }
]

This is my code to plot the map and data points on it.

// load map data
d3.json(mapDataUrl, mapData => {
  const countries = topojson.feature(mapData, mapData.objects.countries).features

  g.selectAll('.country')
    .data(countries)
    .enter().append('path')
    .attr('class', 'country')
    .attr('d', path)
    .on('mouseover', function (d) {
      d3.select(this).classed('hovered', true)
    })
    .on('mouseout', function (d) {
      d3.select(this).classed('hovered', false)
    })
    .on('click', clicked)

  // load ip data
  d3.json(dataUrl, data => {
    const colorScale = d3.scaleOrdinal(d3.schemeBlues[2000]);

    g.selectAll('.meteor')
      .data(data.features)
      .enter().append('circle')
      .attr('class', 'meteor')
      .attr('r', d => calcRad(20000))
      .attr('fill', d => 'blue')
      .attr('cx', d => projection([d.properties.loc.split(', ')[1], d.properties.loc.split(', ')[0]])[0])
      .attr('cy', d => projection([d.properties.loc.split(', ')[1], d.properties.loc.split(', ')[0]])[1])
      .on('mouseover', handleMouseOver)
      .on('mouseout', handleMouseOut)
  })
})

How do I do this, filling the color to the country which is in my custom data?
Thanks for the help.

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!