How do I get d3 to treat missing values as null instead of zero?

谁都会走 提交于 2020-04-11 11:23:38

问题


JSBin of my example with code

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

enter image description here

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,

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?


回答1:


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


来源:https://stackoverflow.com/questions/26387359/how-do-i-get-d3-to-treat-missing-values-as-null-instead-of-zero

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!