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

224
Vistas
Using datamaps, I am trying to create a color for each department

I'm using datamaps (http://datamaps.github.io/) and trying to make a color for each department that have an interval according to the if condition in a France map.

For example if interval == "1-50" make a red color for all the departments that are in this interval, and add this to

data: {
    "mydepartment1": {
      fillKey: "red",
    },
    "mydepartment2": {
      fillKey: "gt50",
    }
  }

This is my js : import departement_list from "../data/departements-list.json";

var jsonData = JSON.parse(JSON.stringify(departement_list));
const dataValues = jsonData.map((data) => data.Departement);
const uniqueValues = [...new Set(dataValues)];

let interval,
nb_votes = [];
for (const valeur of uniqueValues) {
  nb_votes = dataValues.filter((v) => v == valeur).length;
  if (nb_votes <= 0) {
    interval = "defaultFill";
  } else if (nb_votes > 1 && nb_votes < 50) {
    interval = "1-50";
  } else if (nb_votes > 51 && nb_votes < 100) {
    interval = "51-100";
  } else if (nb_votes > 101 && nb_votes < 150) {
    interval = "101-150";
  } else if (nb_votes > 151 && nb_votes < 200) {
    interval = "151-200";
  } else if (nb_votes > 201 && nb_votes < 300) {
    interval = "201-300";
  } else if (nb_votes > 301 && nb_votes < 400) {
    interval = "301-400";
  } else {
    interval = "401-";
  }
}

var map = new Datamap({
  scope: "fra",
  element: document.getElementById("map-france"),
  responsive: true,
  fills: {
    defaultFill: "#EDE8D6",
    "1-50": "#F4F1E6",
    "51-100": "#EDE8D6",
    "101-150": "#E2DABF",
    "151-200": "#CEC191",
    "201-300": "#BCAE7C",
    "301-400": "#9D893E",
    "401-": "#827131",
  },
  data: {
    "mydepartment1": {
      fillKey: "101-150",
    },
    "mydepartment2": {
      fillKey: "151-200",
    }
  }
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Hi it's not clear what your code is meant to do, interval never seems to get used and just get's reset with each iteration of uniqueValues

I've looked up how to use datamaps it looks like the fill "key" corresponds to the fillKey in the data parameter

so for

data: {
    "mydepartment1": {
      fillKey: "red",
    },
    "mydepartment2": {
      fillKey: "gt50",
    }
  }

To work you would need

fills: {
    defaultFill: "#EDE8D6",
    "red": "#F4F1E6",
    "gt50": "#EDE8D6",
  },

I found this blog post that goes into it in more detail. Hopefully that puts you on the right path

about 4 years ago · Juan Pablo Isaza Denunciar
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