i dont know how to improve my following code - it seems a litte bit ugly:
my data is like:
date d1 d2 d3 d4 d5 d6
110522 5 1 3 5 0 7
110523 9 2 4 6 5 9
110524 0 0 0 0 1 0
110525 0 0 3 0 4 0
...
I read in data from a text-file with d3.js and want to generate an "complete" array with following structure:
Array [ Array[10], Array[10], Array[10], Array[10], Array[10] ]
// 10 f.e. is the number of data rows in file
var final1=[];
var final2=[];
var final3=[];
var complete=[];
var dsv = d3.dsv(" ", "text/plain");
dsv("/data/file.txt", function(error, data) {
data.forEach(function(d) {
final1.push({x: d.date, y: d.d1});
final2.push({x: d.date, y: d.d2});
final3.push({x: d.date, y: d.d3});
...
complete.push(final1);
complete.push(final2);
complete.push(final3);
...
});
That code works! But it's very laborious. How can i combine the arrays in an overall array, without the detour of generating a lots of help arrays (final1, final2, ...)?
So end up in an array as follows:
var complete= [
[{'x':110522,'y':5},{'x':110523,'y':9},{'x':110524,'y':0}, ...],
[{'x':110522,'y':1},{'x':110523,'y':2},{'x':110524,'y':0}, ...],
...
];