Considering a dataset like this:
var pie_data = [{
"hard_skill": "Strategy",
"course_area_percentage": 9
}, {
"hard_skill": "Analytics",
"course_area_percentage": 18
}, {
"hard_skill": "Economics",
"course_area_percentage": 11
}, {
"hard_skill": "Finance",
"course_area_percentage": 7
}, {
"hard_skill": "HR",
"course_area_percentage": 5
}, {
"hard_skill": "Innovation",
"course_area_percentage": 2
}, {
"hard_skill": "International",
"course_area_percentage": 5
}, {
"hard_skill": "Marketing",
"course_area_percentage": 7
}, {
"hard_skill": "Operations",
"course_area_percentage": 14
}, {
"hard_skill": "Others",
"course_area_percentage": 11
}, {
"hard_skill": "Project",
"course_area_percentage": 11
}]
I'm creating a pie chart in order to show all of these skills as slices of the chart. The idea then is to give a greener color (meaning it is more important), from a red to green color scale, to the skill that has higher percentage.
I've tried using d3.scale.ordinal() and d3.scale.linear() with different ranges and domains, but the colors do not match to the pattern described above. They seem to be inverted, like this:
My code for the color scale:
var pie_colorScale = d3.scale.ordinal()
//.domain([0,pie_data.length])
//.range(["#d7191c", "#eef200", "#008e15"]);
//.range(["#d7191c","#f19d00","#eef200","#3fe256", "#008e15"]);
.range(["#008e15", "#3fe256", "#eef200", "#f19d00", "#d7191c"]);
Does the mapping of the colors to the values have to be manually set?
