从d3.nest捕获leaves.length值 [英] Capturing leaves.length value from d3.nest

查看:86
本文介绍了从d3.nest捕获leaves.length值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是tsv档案的范例资料:

Here is the sample data from a tsv file:

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如下:

I am using d3.nest as follows:

  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);

我试图按年份绘制半径圆:

And am trying to draw circles of radius according to the count by year:

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 parsing r属性。

d.values is returning NaN parsing r attribute. I have tried getting at this value a variety of ways but it's not working.

推荐答案

d.values

d.values is an array.

而不是这样:

.attr("r", function(d) { return d.values*1.5;})

您应该这样做,因为您想根据年度计数计算半径

you should be doing this since you want to calculate radius according to the count by year:

.attr("r", function(d) {return d.values.length*1.5;})

这篇关于从d3.nest捕获leaves.length值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆