score:1

in this case, you need some custom data formatting. below you may find the code which takes the .csv data you provided us before, then parses it, groups and formats. after that creates gantt project chart. this code helps to get the data structure you want.

//parse .csv data and group by workstation_id
d3.csv("data.csv", function (data1) {
    var workstation = d3.nest()
        .key(function (d) {
            return d.workstation_id;
        })
        .entries(data1);

    //get formatted data as a tree
    var formatteddata = formatdata(workstation);
    console.log(formatteddata);

    //set formatted data as a tree
    var treedata = anychart.data.tree(formatteddata, "as-tree");
    // chart type
    chart = anychart.ganttproject();

    // set data for the chart
    chart.data(treedata);

    // set container id for the chart
    chart.container('container').draw();

    // fit all visible data to timeline.
    chart.fitall();
});

//helper function to format data in apropriate way
//to set to the gantt chart
function formatdata(data) {

    var outputdata = [];

    data.foreach(function (item) {
        var itemobj = {};
        itemobj['name'] = item['key'];
        itemobj['children'] = [];

        var childs = item['values'];

        for (var i = 0; i < childs.length; i++) {
            var childobj = {};
            childobj['name'] = 'order id: ' + childs[i]['order_id'] + '-' + i;
            childobj['actualstart'] = new date(childs[i]['scheduledtime']).gettime();
            childobj['actualend'] = childobj['actualstart'] + childs[i]['duration(seconds)'] * 1000;
            childobj['order_id'] = childs[i]['order_id'];
            itemobj['children'].push(childobj);
        }
        outputdata.push(itemobj);
    });
    return outputdata;
}

below is a screenshot of the chart which is built by this code. enter image description here


Related Query