highchartsgantt-chartgant

Add series / data to highchart gantt from function


My series are like this:

series: [{
                    name: 'Test',
                    data: [{
                        start: Date.UTC(2017, 10, 18, 8, 20), 
                        end: Date.UTC(2017, 10, 18, 11, 30),
                        name: 'One', 
                        assignee: 'Username', 
                        y: 0 
                    },
                    {
                        start: Date.UTC(2017, 10, 18, 14, 20),
                        end: Date.UTC(2017, 10, 18, 16, 0),
                        name: 'Start prototype',
                        assignee: 'Username 2',
                        y: 0
                    }]
                }],

And i was thinking on something along these lines to add an additional event into the gantt chart:

  var chart = $('#container').Highcharts;
                newData = {

                    start: Date.UTC(2017, 10, 19, 18, 20), 
                    end: Date.UTC(2017, 10, 19, 19, 30), 
                    name: 'Nome cliente, Paese', 
                    assignee: 'Username 3', 
                    y: 1 
                }

                chart.addSeries({
                    name: 'New',
                    data:newData
                });

What's the proper way to insert a new data/series from a function?


Solution

  • I prepared a demo which should help you to implement data adding functionality to your project.

    chart.addSeries({
        data: [{
          start: today + day * Math.floor(Math.random() + i),
          end: today + day * Math.floor(Math.random() + i * 2),
          name: 'test' + i,
        }]
    });
    

    Demo: https://jsfiddle.net/BlackLabel/ue2xg6o7/1/

    API: https://api.highcharts.com/class-reference/Highcharts.Chart#addSeries

    Let me know if you have any further questions.