【发布时间】:2017-03-01 18:41:21
【问题描述】:
考虑这样的数据集:
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
}]
我正在创建一个饼图,以便将所有这些技能显示为图表的切片。然后的想法是为具有更高百分比的技能提供更绿的颜色(意味着它更重要),从红色到绿色的颜色等级。
我尝试使用具有不同范围和域的d3.scale.ordinal() and d3.scale.linear(),但颜色与上述模式不匹配。它们似乎是倒置的,像这样:
我的色标代码:
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"]);
颜色到值的映射是否必须手动设置?
【问题讨论】:
标签: javascript d3.js charts pie-chart