如何使d3将缺失值视为空而不是零? [英] How do I get d3 to treat missing values as null instead of zero?

查看:125
本文介绍了如何使d3将缺失值视为空而不是零?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例中的JSBin代码

我在不同的轴上有两个变量的折线图:

I have a line chart of two variables on separate axes:

.csv文件在蓝色系列(关闭")的开头和结尾缺少值:

The .csv file has missing values at the beginning and end for the blue series ('close'):

date,open,close
1-May-89,161,
1-May-90,170,
1-May-91,137,
1-May-92,144,91.9
1-May-93,91,91.8

(...)

1-May-11,12,75.7
1-May-12,7,68.2
1-May-13,15,

结尾处的缺失值已得到正确处理(该行被截断了),但前三个被视为零值.我怎样才能看到蓝色的关闭"系列开始于1992年?

The missing value at the end is handled properly (the line is truncated), but the first three are treated as zero values. How can I have the blue, 'close' series start at 1992?

推荐答案

使用@mccannf的建议修复后,我将一个代码段更改为:

Fixed by using @mccannf's suggestion, I changed one block to:

var valueline = d3.svg.line()
    .defined(function(d) { return d.close != 0; }) // added this line
    .x(function(d) { return x(d.date); })
    .y(function(d) { return y0(d.close); });

由于某些原因,即使示例中引用了以下内容,也无法使用:

For some reason, the following didn't work, even though it's what's cited in the example:

.defined(function(d) { return d.close != null; })

这篇关于如何使d3将缺失值视为空而不是零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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