Drawing non-continuous lines with d3

前端 未结 1 937
耶瑟儿~
耶瑟儿~ 2020-12-09 16:15

I\'m using d3.js to make a simple line graph. I want to know if there\'s a way to create \"holes\" in the graph, that is, if the line can be interrupted or cut when there is

1条回答
  •  独厮守ぢ
    2020-12-09 16:25

    The D3 line generator has a built in function to do just this, line.defined. You can use this function to control where your line is defined and where it is not (like where you have missing data.) If you wanted to make your line undefined whenever the second value in the point array is a javascript NaN value, you could say:

    line.defined(function(d) { return !isNaN(d[1]); });
    

    Here is a good example of this in action.

    0 讨论(0)
提交回复
热议问题