Generating an Array Dynamically with N objects from a JSON File
var taskArray = [];
d3.json("input.json", function(error, json) {
if (error)
return console.warn(error);
for ( var i = 0; i < json.length; i++) {
//console.log(json[i][0]);
var tasks = [];
var version = json[i][1];
var phase = json[i][2];
var part = version + "(" + phase + ")";
var name = json[i][0];
taskArray[i]={
"task" : part,
"type" : name,
"startTime" : json[i][3],
"endTime" : json[i][4]
};
// console.log(taskArray);
}
});
JSON file Format :
[["abc","abc_15.0.1","Intital_phase","Tue Jul 26 21:00:00 2016","Thu Jul 28 09:00:00 2016"]]
If I provide the Array values statically, it works:
var taskArray = [
{
task: "abc_15.0.1 (Intital_phase) ",
type: "abc",
startTime: "Mon Aug 01 06:00:00 2016", //year/month/day
endTime: "Mon Aug 01 14:00:00 2016",
},
];
var dateFormat = d3.time.format("%a %b %e %H:%M:%S %Y");
var timeScale = d3.time.scale()
.domain([d3.min(taskArray, function(d) {return dateFormat.parse(d.startTime);}),
d3.max(taskArray, function(d) {return dateFormat.parse(d.endTime);})])
.range([0,w]);
Is the structure of the Array object not correct? Am I accessing the object values incorrectly? I am having difficulty identifying the issue.