简体   繁体   English

如何在D3.js中的svg上显示一条直线?

[英]How to display a straight line on svg in D3.js?

I have a conundrum. 我有一个难题。 I have a piece of code here that is a slightly modified example of the "multi-series" gallery example (sorry, 10 rep and can't link more than twice) and uses this .tsv file . 我在这里有一段代码,是对“多系列”画廊示例的稍作修改的示例(很抱歉,代表10次,并且不能链接两次以上),并使用此.tsv文件 The expectation is to have the data that currently plots in the code (the "stream" column) on the same SVG with the data that doesn't graph (the +Avgstream and -Avgstream) columns. 期望使当前绘制在同一SVG上的代码(“ stream”列)中的数据与不绘制图形的数据(+ Avgstream和-Avgstream)相同。 However, in each D3.js project I've done, I've never been able to put straight lines on the graph. 但是,在我完成的每个D3.js项目中,我始终无法在图表上画直线。 In this graph at the moment, only the stream column plots. 目前,在此图中,仅显示流列。 It's my attempt at an easy way to show that the results of stream are inside or outside of the running average of the data I'm using. 我试图以一种简单的方法来表明流的结果在我正在使用的数据的运行平均值的内部或外部。

Any ideas on why these lines won't plot? 关于这些线为何无法绘制的任何想法?

Are you just trying to plot all three series? 您是否只是想绘制所有三个系列? There should be no problem, except that it appears your column names in tsv file include the "+" and "-" character which I'm not sure is allowed: 应该没有问题,除了在tsv文件中您的列名称包含“ +”和“-”字符(我不确定是否允许)外:

Unixtime        stream  +Avgstream      -Avgstream
1351805809      5594    5489    6379
1351865010      5468    5489    6379
1351868732      5479    5489    6379
1351875915      5504    5489    6379
1351883184      7177    5489    6379
1351890345      5481    5489    6379
...

I replaced your column names (and tsv decoding) with: 我用以下代码替换了您的列名(和tsv解码):

data = [
    {Unixtime:1351805809, stream: 5594, plusavg:5489, lessavg:6379},
    {Unixtime:1351865010, stream: 5468, plusavg:5489, lessavg:6379},
    {Unixtime:1351868732, stream: 5479, plusavg:5489, lessavg:6379},
    {Unixtime:1351875915, stream: 5504, plusavg:5489, lessavg:6379},
    {Unixtime:1351883184, stream: 7177, plusavg:5489, lessavg:6379}
];

And I get three lines in the chart: 我在图表中得到了三行:

在此处输入图片说明

Is that sort of what you are trying to do? 这就是您要尝试的吗? See here . 这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM