简体   繁体   中英

d3.js Gantt chart

var tasks;   
d3.json("http://localhost:8080/result", function(error, data) {   
tasks = data   
data.forEach(function(d) {   
d.startDate = new Date(d.maxTime["$date"]);   
d.endDate = new Date(d.minTime["$date"]);   
});   

var taskNames = ["Bob", "Sam"];   

var gantt = d3.gantt().taskTypes(taskNames);   
gantt(data);   
});  

I am using help from here This is what the my array of json objects returned from http://localhost:8080/result looks like:

[
  {"minTime": {"$date": 1459555200000},
    "maxTime": {"$date": 1459555860000},
    "Time": 660.0, "Name": "Sam"},  
  {"minTime": {"$date": 1459558800000},
    "maxTime": {"$date": 1459563265000},
    "Time": 4465.0, "Name": "Bob"},  
  {"minTime": {"$date": 1459562400000},
    "maxTime": {"$date": 1459563842000},
    "Time": 1442.0, "Name": "Sam"},  
    ...  
]

I am getting an error

A negative value is not valid. ("-30.00296 864734321")

and 397 others.

What do these errors mean?

Try

d.startDate = new Date(d.maxTime.$date);   
d.endDate = new Date(d.minTime.$date);   

or

d.startDate = new Date(d.maxTime["$date"]);   
d.endDate = new Date(d.minTime["$date"]); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM