sir_thursday
sir_thursday

Reputation: 5409

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:

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

However, my data is currently in three different 2D arrays. Is there a built in d3 function that I can use to plot three lines on the same graph with this data? Or do I have to manually construct three lines and add each of them to the svg.

Upvotes: 1

Views: 1374

Answers (1)

adilapapaya
adilapapaya

Reputation: 4795

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? E.g. 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.    
     });

Upvotes: 3

Related Questions