以下是来自tsv文件的示例数据:
college dept year
College of Education, Health & Human Development Education. 2011
College of Letters & Science Earth Sciences. 2010
College of Letters & Science Microbiology & Immunology. 2004
College of Letters & Science Ecology. 1984
College of Letters & Science Chemistry & Biochemistry. 2008
College of Letters & Science Mathematical Sciences. 2011
College of Agriculture Land Resources & Environmental Sciences. 2009
College of Agriculture Agricultural Economics & Economics. 1996
College of Letters & Science English. 2007
College of Letters & Science Cell Biology & Neuroscience. 2011
College of Agriculture Land Resources & Environmental Sciences. 2012
Graduate School Intercollege Programs for Science Education. 2012
Graduate School Intercollege Programs for Science Education. 2011
College of Engineering Mechanical & Industrial Engineering. 2007
College of Engineering Industrial Engineering. 2005
College of Agriculture Agricultural Economics & Economics. 1986
College of Nursing Nursing. 2007
College of Letters & Science Microbiology & Immunology. 2006
College of Agriculture Agricultural Economics & Economics. 1974
我正在使用d3.nest如下:
var deptYearCount = d3.nest()
.key(function(d) { return d.college;} )
.key(function(d) { return d.dept })
.key(function(d) { return d.year })
.rollup(function(leaves) { return leaves.length;})
.entries(dataset);
我正在尝试按年份计算半径圆圈:
svg.selectAll(".dot")
.data(deptYearCount)
.enter().append("circle")
.attr("class", "dot")
.attr("r", function(d) { return d.values*1.5;})
.style("opacity", 0.3)
.style("fill", "#e31a1c" )
.attr("cx", function(d) { return x(d.year); })
.attr("cy", function(d) { return y(d.dept); });
d.values返回NaN解析r属性。我试过以各种方式获得这个价值,但它没有用。
答案 0 :(得分:0)
d.values
是一个数组。
所以不要这样:
.attr("r", function(d) { return d.values*1.5;})
你应该这样做,因为你想根据年份计算半径:
.attr("r", function(d) {return d.values.length*1.5;})