如何在D3中使用嵌套組作爲我的x軸?這是否可能?D3嵌套組爲x軸
我不是我的dev的機器後我的代碼示例,但爲了便於說明,假設從下面的代碼:What is the best way to form age groups from a list in D3?
var nest = d3.nest()
.key(function(d) { return d.sex; })
.key(function(d){
var ageGroup = null;
if (d.age <= 10){
ageGroup = '0-10';
} else if (d.age > 10 && d.age <= 20){
ageGroup = '10-20';
} else if (d.age > 20 && d.age <= 30){
ageGroup = '20-30';
} else if (d.age > 30 && d.age <= 40){
ageGroup = '30-40';
} else if (d.age > 40 && d.age <= 50){
ageGroup = '40-50';
} else if (d.age > 50 && d.age <= 60){
ageGroup = '50-60';
} else if (d.age > 60 && d.age <= 70){
ageGroup = '60-70';
} else if (d.age > 70 && d.age <= 80){
ageGroup = '70-80';
} else if (d.age > 80 && d.age <= 90){
ageGroup = '80-90';
} else if (d.age > 90 && d.age <= 100){
ageGroup = '90-100';
}
return ageGroup;
})
.entries(myArray);
我會怎麼用ageGroup
我的x軸?
你可以使用它作爲順序量表。 – Cyril