1

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.

1 Answer 1

3

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.    
     });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.