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

131
Visualizações
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
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