简体   繁体   English

d3处理多个数组中的数据

[英]d3 handle data in multiple arrays

I'm trying to plot a multi-line graph. 我正在尝试绘制多线图。 I know how to build a d3 graph with one line, and I know how to build a d3 graph with multiple lines with the data is organized as such: 我知道如何用一行构建一个d3图,并且我知道如何用数据构建多行的d3图是这样组织的:

id, value1, value2
1, 10, 20
2, 10, 20
3, ...

However, my data is currently in three different 2D arrays. 但是,我的数据当前位于三个不同的2D数组中。 Is there a built in d3 function that I can use to plot three lines on the same graph with this data? 是否有内置的d3函数,可以使用此数据在同一图形上绘制三条线? Or do I have to manually construct three lines and add each of them to the svg . 还是我必须手动构造三行并将每行添加到svg

Not sure if this answers your question completely but can you combine the three 2D arrays into a single array and then pass that array into your plotting function? 不确定是否可以完全回答您的问题,但是可以将三个2D数组合并为一个数组,然后将该数组传递到绘图函数中吗? Eg something like this: 例如这样的事情:

var data = [data1,data2,data3];
var graph = svg.append('g').selectAll('graph')
               .data(data)
               .enter().append('g')
               .attr('class','graph');

graph.append('path')
     .attr('d',function(dat,i){
         // dat in this case will correspond to the data for
         // for a single curve.
         // This will return the path for
         // graphing a single curve.    
     });

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

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