用 d3 绘制非连续线 [英] Drawing non-continuous lines with d3

查看:42
本文介绍了用 d3 绘制非连续线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 d3.js 制作一个简单的折线图.我想知道是否有办法在图中创建洞",即在没有可用数据的情况下是否可以中断或切割线.

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 no data available.

我正在考虑从域中删除我不需要的位置,或者将特定段中的线宽设置为 0,但我找不到任何一种方法.

I'm looking into either delete the places I don't need from the domain, or setting the line weight to 0 in specific segments, but I can't find a way to do either of these.

感谢您的帮助!

推荐答案

D3 线 生成器有一个内置函数来执行此操作,line.defined.您可以使用此函数来控制线的定义位置和不定义位置(例如丢失数据的位置.)如果您想让点数组中的第二个值是 javascript NaN 值时取消定义您的线,您可以说:

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

这里就是一个很好的例子.

这篇关于用 d3 绘制非连续线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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