I have the code, where I load data from a csv file and get the data by grouping data using D3.
The code I wrote is:
d3.csv("data/data2.csv", function(data1) {
var workStation =
{"key":"Data","values":
d3.nest()
.key(function(d) { return d.WorkStation_Id; })
.key(function(d) { return d.Order_Id; })
.rollup(function(v) {
return v.map(function(c){
return { "actualStart": convertscheduledtime(c.ScheduledTime),"rowHeight": 30, "actualEnd":c.Duration*1000+convertscheduledtime(c.ScheduledTime), "name":c.Order_Id};
});
}).entries(data1)};
var d2= [{"name":"Data", "children":workStation.values.map( function(major){
return {
"name": major.key,
"children":major.values.map( function(Order_Id){
return{
"name" : Order_Id.key,
"actualStart" : Order_Id.values.actualStart,
"actualEnd" : Order_Id.values.actualEnd
};
})
};
})
}];
});
console.log(d2);
What I was trying to do was convert the obtained result to json format using the following code which I found online: These are the following I am trying to do:
1) I am trying to get the Start Time End Time. I am calculating the Start time by adding the Duration. 2) The array that is obtained is coming as nested key values pair. I am trying to convert them to JSON data so that I can just pass this into the var treeData Gantt chart of anychart.js.
The following is the JSON data what I am trying to achieve and I got the data that I want till children's name:1, for actualStart and actualEnd I am getting undefined as the value:
parent : 10A,
children:[{
name:1,
actualStart:18332233333,
actualEnd:12343434444},
{
name:2,
actualStart:18332233898,
actualEnd:12343434998},
....
],
parent : 10B,
children: [{
name:1,
actualStart:18332233333,
actualEnd:12343434444},
{
name:2,
actualStart:18332233898,
actualEnd:12343434998},
....
]
....
Could someone kindly suggest what I need to change to get the actualStart and actualEnd data.
Thank you.
I have included the sample csv data:
ScheduledTime,WorkStation_Id,Order_Id,Duration(seconds)
01.01.2016 00:00:00,10A,1,15
01.01.2016 00:00:15,10A,1,25
01.01.2016 00:00:35,10A,1,10
01.01.2016 00:00:45,10A,2,10
01.01.2016 00:00:55,10A,2,10
01.01.2016 00:01:05,10B,1,20
01.01.2016 00:01:25,10B,1,10
01.01.2016 00:01:35,10B,2,20
.....
