I have a csv file which load into screen . The csv File has following attributes
DATE MESSAGEID Status Source ParentID childID
12/21/2013 23:12 123 SEND A 2
12/21/2013 23:12 456 RECEIVE B 3
12/21/2013 23:12 789 SEND B 2 4
Now in console I wrote this
var csvdataset;
d3.csv("newFile.csv",function(d,i){csvdataset=i;console.log(csvdataset)});
So it gives me
[Object, Object, Object]
Now if I want to retrieve the message id or any value how do I get those from ? I know if I give
d3.csv("newFile.csv",function(d,i){csvdataset=i;console.log(csvdataset[3])});
I will get the third row but I need some Kind of loop that will execute to retrieve a particular value from an object .
I have tried below things
d3.csv("newFile.csv", function (d, i) {
csvdataset = i;
}, csvdataset.forEach(csvdataset) {
alert(csvdataset.SOURCE[csvdataset]);
}
});
d3.csv("newFile.csv", function (d, i) {
csvdataset = i;
console.log(i.SOURCESERVICE[i])
});
but nothing is working .
I have another issue . i am generating a json in tree structure as below
[{"Name":"s1","Node ID":"649","DataObject":{"nodeID":"649","nodeName":"s1","timeTaken":"00:06:30","startTime":"2013-12-10 18:06:02"},"Children":[[{"Name":"c1","Node ID":"286","DataObject":{"nodeID":"286","nodeName":"c1","timeTaken":"00:06:27","startTime":"2013-12-10 18:06:04+05:30"},"Children":[[{"Name":"c2","Node ID":"287","DataObject":{"nodeID":"287","nodeName":"c2","timeTaken":"00:00:02","startTime":"2013-12-10 18:06:06+05:30"}},{"Name":"c3","Node ID":"1080","DataObject":{"nodeID":"1080","nodeName":"c3","timeTaken":"00:06:17","startTime":"2013-12-10 18:06:12+05:30"},"Children":[[{"Name":"c4","Node ID":"b2861a2f-75a9-4f95-abcd-1dae54e713bc","DataObject":{"nodeID":"b2861a2f-75a9-4f95-abcd-1dae54e713bc","nodeName":"c4","timeTaken":"00:05:08","startTime":"2013-12-10 18:07:19+05:30"}}]]}]]}]]}]
now i am trying to create a tree in d3 . But i am unable to retrieve the children
var tree = d3.layout.tree()
.size([height, width])
.children(function(d)
{
return (!d.Children || d.Children.length === 0) ? null : d.Children;
});
d3.xhr("DataMapper?function-name=Tree","application/json", function(error, flare) {
root = JSON.parse(flare.response);
root.x0 = height / 2;
root.y0 = 0;
console.log(root);
function collapse(d) {
if (d.Children) {
d.Children= d.Children;
d.Children.forEach(collapse);
d.Children= null;
console.log("children "+d.Children);
}
}
});
if i am givingvar nodes = tree.nodes(root); i get a array of nodes in the nodes variable but if i give var links=tree.links(nodes); i am unable to get the links . Could any one explain this .I have provided the json above