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

231
Views
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 answers
Answer question

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 Report
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!