I am having trouble understanding why my code won't work.

我无法理解为什么我的代码不起作用。

I am getting an error on .attr('r', function(d)

我在.attr('r',函数(d)上收到错误

I am assigning a number to year and creating a variable called category by adding d.p and year. The name of each data category in my csv file is p1900, p1901, p1902, p1903, etc. And I try to access it in .attr('r', function(d) but it doesn't seem to register.

我正在为年份分配一个数字,并通过添加d.p和year创建一个名为category的变量。我的csv文件中每个数据类别的名称是p1900,p1901,p1902,p1903等。我尝试在.attr('r',函数(d)中访问它但它似乎没有注册。

  cityPoints.attr('cx', function(d) {return projection([d.lon, d.lat])[0]})
       .attr('cy', function(d) {return projection([d.lon, d.lat])[1]})
       .attr('r', function(d) {

       var category = "d.p"+year;
           if (scale(category) != null) {return scale(category) + 'px'}
           else {return '0px'};
           ;})
       .attr('stroke', 'white');

1 个解决方案

#1


0

You're not actually accessing the d object, just working on a string called d.p1900 instead.

你实际上并没有访问d对象,只是处理一个名为d.p1900的字符串。

Try doing this:

试着这样做:

cityPoints.attr('cx', function(d) {return projection([d.lon, d.lat])[0]})
    .attr('cy', function(d) {return projection([d.lon, d.lat])[1]})
    .attr('r', function(d) {

        var category = "p" + year;
        if (scale(d[category]) != null) {
            return scale(d[category]) + 'px';
        } else { return '0px' };

    }).attr('stroke', 'white');

更多相关文章

  1. 求助 急 js替换字符串问题
  2. 如何判断字符串是一个字符串化的JSON对象
  3. 在传递给google.setOnLoadCallback()的函数中使用参数;
  4. 另一个iframe中的iframe的onload函数
  5. JavaScript相当于Ruby的字符串#扫描
  6. JavaScript 中的函数介绍
  7. 11、javascript中字符串常用操作总结、JS字符串操作大全
  8. 从占用转义字符的字符数组创建字符串
  9. javascript如何取字符串中的数字

随机推荐

  1. Android Filetransfer错误码3
  2. Android——Tomcat版本更新下载+头像照片
  3. Android两种方式监听短信内容---Broadcas
  4. 如何通过MigLayout手动计算宽度
  5. Ubuntu 14.04搭建Android5.1开发环境和编
  6. 【android】在Eclipse中关联所引用的jar
  7. 如何从android的联系人姓名中获取联系人
  8. 求教:如何通过JNI调用手机自身摄像头录像
  9. android开发之流量监控
  10. 探秘腾讯Android手机游戏平台之不安装游